Interface Wire
-
public interface WireA connection between a Producer service and a Consumer service.A
Wireobject connects a Producer service to a Consumer service. Both the Producer and Consumer services are identified by their uniqueservice.pidvalues. The Producer and Consumer services may communicate with each other viaWireobjects that connect them. The Producer service may send updated values to the Consumer service by calling theupdate(Object)method. The Consumer service may request an updated value from the Producer service by calling thepoll()method.A Producer service and a Consumer service may be connected through multiple
Wireobjects.Security Considerations.
Wireobjects are available to Producer and Consumer services connected to a givenWireobject and to bundles which can access theWireAdminservice. A bundle must haveServicePermission[WireAdmin,GET]to get theWireAdminservice to access allWireobjects. A bundle registering a Producer service or a Consumer service must have the appropriateServicePermission[Consumer|Producer,REGISTER]to register the service and will be passedWireobjects when the service object'sconsumersConnectedorproducersConnectedmethod is called.Scope. Each Wire object can have a scope set with the
setScopemethod. This method should be called by a Consumer service when it assumes a Producer service that is composite (supports multiple information items). The names in the scope must be verified by theWireobject before it is used in communication. The semantics of the names depend on the Producer service and must not be interpreted by the Wire Admin service.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Class<?>[]getFlavors()Return the list of data types understood by the Consumer service connected to thisWireobject.java.lang.ObjectgetLastValue()Return the last value sent through thisWireobject.java.util.Dictionary<java.lang.String,java.lang.Object>getProperties()Return the wire properties for thisWireobject.java.lang.String[]getScope()Return the calculated scope of thisWireobject.booleanhasScope(java.lang.String name)Return true if the given name is in thisWireobject's scope.booleanisConnected()Return the connection state of thisWireobject.booleanisValid()Return the state of thisWireobject.java.lang.Objectpoll()Poll for an updated value.voidupdate(java.lang.Object value)Update the value.
-
-
-
Method Detail
-
isValid
boolean isValid()
Return the state of thisWireobject.A connected
Wiremust always be disconnected before becoming invalid.- Returns:
falseif thisWireobject is invalid because it has been deleted viaWireAdmin.deleteWire(Wire);trueotherwise.
-
isConnected
boolean isConnected()
Return the connection state of thisWireobject.A
Wireis connected after the Wire Admin service receives notification that the Producer service and the Consumer service for thisWireobject are both registered. This method will returntrueprior to notifying the Producer and Consumer services via calls to their respectiveconsumersConnectedandproducersConnectedmethods.A
WireAdminEventof typeWireAdminEvent.WIRE_CONNECTEDmust be broadcast by the Wire Admin service when theWirebecomes connected.A
Wireobject is disconnected when either the Consumer or Producer service is unregistered or theWireobject is deleted.A
WireAdminEventof typeWireAdminEvent.WIRE_DISCONNECTEDmust be broadcast by the Wire Admin service when theWirebecomes disconnected.- Returns:
trueif both the Producer and Consumer for thisWireobject are connected to theWireobject;falseotherwise.
-
getFlavors
java.lang.Class<?>[] getFlavors()
Return the list of data types understood by the Consumer service connected to thisWireobject. Note that subclasses of the classes in this list are acceptable data types as well.The list is the value of the
WireConstants.WIREADMIN_CONSUMER_FLAVORSservice property of the Consumer service object connected to this object. If no such property was registered or the type of the property value is notClass[], this method must returnnull.- Returns:
- An array containing the list of classes understood by the
Consumer service or
nullif theWireis not connected, or the consumer did not register aWireConstants.WIREADMIN_CONSUMER_FLAVORSproperty or the value of the property is not of typeClass[].
-
update
void update(java.lang.Object value)
Update the value.This methods is called by the Producer service to notify the Consumer service connected to this
Wireobject of an updated value.If the properties of this
Wireobject contain aWireConstants.WIREADMIN_FILTERproperty, then filtering is performed. If the Producer service connected to thisWireobject was registered with the service propertyWireConstants.WIREADMIN_PRODUCER_FILTERS, the Producer service will perform the filtering according to the rules specified for the filter. Otherwise, thisWireobject will perform the filtering of the value.If no filtering is done, or the filter indicates the updated value should be delivered to the Consumer service, then this
Wireobject must call theConsumer.updated(Wire, Object)method with the updated value. If thisWireobject is not connected, then the Consumer service must not be called and the value is ignored.If the value is an
Envelopeobject, and the scope name is not permitted, then theWireobject must ignore this call and not transfer the object to the Consumer service.A
WireAdminEventof typeWireAdminEvent.WIRE_TRACEmust be broadcast by the Wire Admin service after the Consumer service has been successfully called.- Parameters:
value- The updated value. The value should be an instance of one of the types returned bygetFlavors().- See Also:
WireConstants.WIREADMIN_FILTER
-
poll
java.lang.Object poll()
Poll for an updated value.This methods is normally called by the Consumer service to request an updated value from the Producer service connected to this
Wireobject. ThisWireobject will call theProducer.polled(Wire)method to obtain an updated value. If thisWireobject is not connected, then the Producer service must not be called.If this
Wireobject has a scope, then this method must return an array ofEnvelopeobjects. The objects returned must match the scope of this object. TheWireobject must remove allEnvelopeobjects with a scope name that is not in theWireobject's scope. Thus, the list of objects returned must only containEnvelopeobjects with a permitted scope name. If the array becomes empty,nullmust be returned.A
WireAdminEventof typeWireAdminEvent.WIRE_TRACEmust be broadcast by the Wire Admin service after the Producer service has been successfully called.- Returns:
- A value whose type should be one of the types returned by
getFlavors(),Envelope[], ornullif theWireobject is not connected, the Producer service threw an exception, or the Producer service returned a value which is not an instance of one of the types returned bygetFlavors().
-
getLastValue
java.lang.Object getLastValue()
Return the last value sent through thisWireobject.The returned value is the most recent, valid value passed to the
update(Object)method or returned by thepoll()method of this object. If filtering is performed by thisWireobject, this methods returns the last value provided by the Producer service. This value may be anEnvelope[]when the Producer service uses scoping. If the return value is an Envelope object (or array), it must be verified that the Consumer service has the proper WirePermission to see it.- Returns:
- The last value passed though this
Wireobject ornullif no valid values have been passed or the Consumer service has no permission.
-
getProperties
java.util.Dictionary<java.lang.String,java.lang.Object> getProperties()
Return the wire properties for thisWireobject.- Returns:
- The properties for this
Wireobject. The returnedDictionarymust be read only.
-
getScope
java.lang.String[] getScope()
Return the calculated scope of thisWireobject. The purpose of theWireobject's scope is to allow a Producer and/or Consumer service to produce/consume different types over a singleWireobject (this was deemed necessary for efficiency reasons). Both the Consumer service and the Producer service must set an array of scope names (their scope) with the service registration propertyWIREADMIN_PRODUCER_SCOPE, orWIREADMIN_CONSUMER_SCOPEwhen they can produce multiple types. If a Producer service can produce different types, it should set this property to the array of scope names it can produce, the Consumer service must set the array of scope names it can consume. The scope of aWireobject is defined as the intersection of permitted scope names of the Producer service and Consumer service.If neither the Consumer, or the Producer service registers scope names with its service registration, then the
Wireobject's scope must benull.The
Wireobject's scope must not change when a Producer or Consumer services modifies its scope.A scope name is permitted for a Producer service when the registering bundle has
WirePermission[name,PRODUCE], and for a Consumer service when the registering bundle hasWirePermission[name,CONSUME].If either Consumer service or Producer service has not set a
WIREADMIN_*_SCOPEproperty, then the returned value must benull.If the scope is set, the
Wireobject must enforce the scope names whenEnvelopeobjects are used as a parameter to update or returned from thepollmethod. TheWireobject must then remove allEnvelopeobjects with a scope name that is not permitted.- Returns:
- A list of permitted scope names or null if the Produce or Consumer service has set no scope names.
-
hasScope
boolean hasScope(java.lang.String name)
Return true if the given name is in thisWireobject's scope.- Parameters:
name- The scope name- Returns:
- true if the name is listed in the permitted scope names
-
-