Package net.jini.space
Interface JavaSpace
- All Known Subinterfaces:
IDirectSpaceProxy,ISpaceProxy
- All Known Implementing Classes:
AbstractDirectSpaceProxy,AbstractSpaceCacheContainer,AbstractSpaceProxy,LocalCacheContainer,LocalViewContainer,SpaceProxyImpl
public interface JavaSpace
This interface is implemented by servers that export a JavaSpaces(TM) technology service. The
operations in this interface are the public methods that all such spaces support.
- Author:
- Sun Microsystems, Inc.
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionnotify(Entry tmpl, Transaction txn, RemoteEventListener listener, long lease, MarshalledObject handback) When entries are written that match this template notify the givenlistenerwith aRemoteEventthat includes thehandbackobject.read(Entry tmpl, Transaction txn, long timeout) Read any matching entry from the space, blocking until one exists.readIfExists(Entry tmpl, Transaction txn, long timeout) Read any matching entry from the space, returningnullif there is currently is none.The process of serializing an entry for transmission to a JavaSpaces service will be identical if the same entry is used twice.take(Entry tmpl, Transaction txn, long timeout) Take a matching entry from the space, waiting until one exists.takeIfExists(Entry tmpl, Transaction txn, long timeout) Take a matching entry from the space, returningnullif there is currently is none.write(Entry entry, Transaction txn, long lease) Write a new entry into the space.
-
Field Details
-
NO_WAIT
static final long NO_WAITWait for no time at all. This is used as a timeout value in various read and take calls.- See Also:
-
read(net.jini.core.entry.Entry, net.jini.core.transaction.Transaction, long)readIfExists(net.jini.core.entry.Entry, net.jini.core.transaction.Transaction, long)take(net.jini.core.entry.Entry, net.jini.core.transaction.Transaction, long)takeIfExists(net.jini.core.entry.Entry, net.jini.core.transaction.Transaction, long)- Constant Field Values
-
-
Method Details
-
write
Write a new entry into the space. Equivalent to callingIPojoSpace.write(Object, Transaction, long, long, int)withUpdateModifiers.WRITE_ONLY.- Parameters:
entry- the entry to writetxn- the transaction object, if any, under which to perform the writelease- the requested lease time, in milliseconds- Returns:
- a lease for the entry that was written to the space
- Throws:
TransactionException- if a transaction error occursRemoteException- if a communication error occurs
-
read
Entry read(Entry tmpl, Transaction txn, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException Read any matching entry from the space, blocking until one exists. Returnnullif the timeout expires.- Parameters:
tmpl- The template used for matching. Matching is done againsttmplwithnullfields being wildcards ("match anything") other fields being values ("match exactly on the serialized form").txn- The transaction (if any) under which to work.timeout- How long the client is willing to wait for a transactionally proper matching entry. A timeout ofNO_WAITmeans to wait no time at all; this is equivalent to a wait of zero.- Returns:
- a copy of the entry read from the space
- Throws:
UnusableEntryException- if any serialized field of the entry being read cannot be deserialized for any reasonTransactionException- if a transaction error occursInterruptedException- if the thread in which the read occurs is interruptedRemoteException- if a communication error occursIllegalArgumentException- if a negative timeout value is used
-
readIfExists
Entry readIfExists(Entry tmpl, Transaction txn, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException Read any matching entry from the space, returningnullif there is currently is none. Matching and timeouts are done as inread, except that blocking in this call is done only if necessary to wait for transactional state to settle.- Parameters:
tmpl- The template used for matching. Matching is done againsttmplwithnullfields being wildcards ("match anything") other fields being values ("match exactly on the serialized form").txn- The transaction (if any) under which to work.timeout- How long the client is willing to wait for a transactionally proper matching entry. A timeout ofNO_WAITmeans to wait no time at all; this is equivalent to a wait of zero.- Returns:
- a copy of the entry read from the space
- Throws:
UnusableEntryException- if any serialized field of the entry being read cannot be deserialized for any reasonTransactionException- if a transaction error occursInterruptedException- if the thread in which the read occurs is interruptedRemoteException- if a communication error occursIllegalArgumentException- if a negative timeout value is used- See Also:
-
take
Entry take(Entry tmpl, Transaction txn, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException Take a matching entry from the space, waiting until one exists. Matching is and timeout done as forread.- Parameters:
tmpl- The template used for matching. Matching is done againsttmplwithnullfields being wildcards ("match anything") other fields being values ("match exactly on the serialized form").txn- The transaction (if any) under which to work.timeout- How long the client is willing to wait for a transactionally proper matching entry. A timeout ofNO_WAITmeans to wait no time at all; this is equivalent to a wait of zero.- Returns:
- the entry taken from the space
- Throws:
UnusableEntryException- if any serialized field of the entry being read cannot be deserialized for any reasonTransactionException- if a transaction error occursInterruptedException- if the thread in which the take occurs is interruptedRemoteException- if a communication error occursIllegalArgumentException- if a negative timeout value is used- See Also:
-
takeIfExists
Entry takeIfExists(Entry tmpl, Transaction txn, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException Take a matching entry from the space, returningnullif there is currently is none. Matching is and timeout done as forread, except that blocking in this call is done only if necessary to wait for transactional state to settle.- Parameters:
tmpl- The template used for matching. Matching is done againsttmplwithnullfields being wildcards ("match anything") other fields being values ("match exactly on the serialized form").txn- The transaction (if any) under which to work.timeout- How long the client is willing to wait for a transactionally proper matching entry. A timeout ofNO_WAITmeans to wait no time at all; this is equivalent to a wait of zero.- Returns:
- the entry taken from the space
- Throws:
UnusableEntryException- if any serialized field of the entry being read cannot be deserialized for any reasonTransactionException- if a transaction error occursInterruptedException- if the thread in which the take occurs is interruptedRemoteException- if a communication error occursIllegalArgumentException- if a negative timeout value is used- See Also:
-
notify
EventRegistration notify(Entry tmpl, Transaction txn, RemoteEventListener listener, long lease, MarshalledObject handback) throws TransactionException, RemoteException When entries are written that match this template notify the givenlistenerwith aRemoteEventthat includes thehandbackobject. Matching is done as forread.- Parameters:
tmpl- The template used for matching. Matching is done againsttmplwithnullfields being wildcards ("match anything") other fields being values ("match exactly on the serialized form").txn- The transaction (if any) under which to work.listener- The remote event listener to notify.lease- the requested lease time, in millisecondshandback- An object to send to the listener as part of the event notification.- Returns:
- the event registration to the the registrant
- Throws:
TransactionException- if a transaction error occursRemoteException- if a communication error occursIllegalArgumentException- if the lease time requested is not Lease.ANY and is negative- See Also:
-
snapshot
The process of serializing an entry for transmission to a JavaSpaces service will be identical if the same entry is used twice. This is most likely to be an issue with templates that are used repeatedly to search for entries withreadortake. The client-side implementations ofreadandtakecannot reasonably avoid this duplicated effort, since they have no efficient way of checking whether the same template is being used without intervening modification. Thesnapshotmethod gives the JavaSpaces service implementor a way to reduce the impact of repeated use of the same entry. Invokingsnapshotwith anEntrywill return anotherEntryobject that contains a snapshot of the original entry. Using the returned snapshot entry is equivalent to using the unmodified original entry in all operations on the same JavaSpaces service. Modifications to the original entry will not affect the snapshot. You cansnapshotanulltemplate;snapshotmay or may not return null given anulltemplate. The entry returned fromsnapshotwill be guaranteed equivalent to the original unmodified object only when used with the space. Using the snapshot with any other JavaSpaces service will generate anIllegalArgumentExceptionunless the other space can use it because of knowledge about the JavaSpaces service that generated the snapshot. The snapshot will be a different object from the original, may or may not have the same hash code, andequalsmay or may not returntruewhen invoked with the original object, even if the original object is unmodified. A snapshot is guaranteed to work only within the virtual machine in which it was generated. If a snapshot is passed to another virtual machine (for example, in a parameter of an RMI call), using it--even with the same JavaSpaces service--may generate anIllegalArgumentException.- Parameters:
e- the entry to take a snapshot of.- Returns:
- a snapshot of the entry.
- Throws:
RemoteException- if a communication error occurs
-