|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IJSpace
This interface represents the application view of a GigaSpace instance. It is implemented by all the Space Proxies (Embedded, Remote and Cluster).
When client receives a proxy to the space from the Lookup Service (see
SpaceFinder
, this proxy implements this interface, and therefore may
be casted to this interface if specific GigaSpaces methods (such as
clean()
) are required.
Since this interface extends the JavaSpace
interface, standard
JavaSpaces methods may be invoked without downcasting.
Scenario B: Fetching a POJO from the space using methods read(), readMultiple(),
readIfExists(), take(), takeMultiple(), takeIfExists() etc:
1. When the POJO has no key property declared, it then will be returned without any UID. It
means that only read() and write() operations can be executed on the POJO and
NOT an update().
2. When the POJO has a key property declared, it then will
be returned with the source value of the property but without the generated
UID. The POJO can not approach the UID which was generated by the space. 3.
The POJO has a property which declared as a key and auto generate - The space
returns the POJO with the generated UID into the property.
IJSpaceContainer
,
SpaceFinder
Field Summary |
---|
Fields inherited from interface net.jini.space.JavaSpace |
---|
NO_WAIT |
Method Summary | |
---|---|
void |
clean()
Cleans this space. |
void |
clear(Entry template,
Transaction txn)
Removes the entries that match the specified template and the specified transaction from this space. |
void |
clear(Object template,
Transaction txn)
Removes the objects that match the specified template and the specified transaction from this space. |
int |
count(Entry template,
Transaction txn)
Counts the number of entries that match the specified template and the specified transaction. |
int |
count(Object template,
Transaction txn)
Counts the number of objects that match the specified template and the specified transaction. |
void |
dropClass(String className)
Drops all Class's entries and all its templates from the space. |
Object |
getAdmin()
Returns the admin object to the remote part of this space. |
IJSpaceContainer |
getContainer()
Returns the container proxy this space resides in. |
String |
getName()
Returns the name of this space. |
int |
getReadTakeModifiers()
Gets the proxyReadTakeModifiers. |
Uuid |
getReferentUuid()
Returns the unique uid of this space instance. |
IStubHandler |
getStubHandler()
Returns the StubHandler of this space. |
int |
getUpdateModifiers()
Gets the proxyUpdateModifiers. |
SpaceURL |
getURL()
Returns the SpaceURL instance which was used to initialize the space. |
boolean |
isEmbedded()
Checks whether proxy is connected to embedded or remote space. |
boolean |
isFifo()
Returns true if this proxy FIFO enabled, otherwise false . |
boolean |
isNOWriteLeaseMode()
Checks the write mode. |
boolean |
isOptimisticLockingEnabled()
Returns status of Optimistic Lock protocol. |
boolean |
isSecured()
Returns an indication : is this space secured. |
EventRegistration |
notify(Entry template,
Transaction txn,
RemoteEventListener listener,
long lease,
MarshalledObject handback,
int notifyType)
An extension to the standard JavaSpace.notify()
method. |
EventRegistration |
notify(Object object,
Transaction transaction,
RemoteEventListener remoteeventlistener,
long lease,
MarshalledObject marshalledobject)
When objects that match this template are written, notification is sent to the given listener with a RemoteEvent that includes the handback object. |
EventRegistration |
notify(Object template,
Transaction txn,
RemoteEventListener listener,
long lease,
MarshalledObject handback,
int modifiers)
An extension to the standard JavaSpace.notify()
method. |
void |
ping()
Checks whether the space is alive and accessible. |
Object |
read(Object entry,
Transaction transaction,
long timeout)
Read any matching object from the space, blocking until one exists. |
Object |
readIfExists(Object object,
Transaction transaction,
long timeout)
Read if exists any matching object from the space, blocking until one exists. |
Entry[] |
readMultiple(Entry template,
Transaction txn,
int maxEntries)
Reads all the entries matching the specified template from this space. |
Object[] |
readMultiple(Object template,
Transaction txn,
int maxEntries)
Reads all the objects matching the specified template from this space. |
Object[] |
replace(Entry template,
Entry newEntry,
Transaction txn,
long lease)
Deprecated. use instead: update(Entry, Transaction, long, long, int) |
void |
setDefaultTransaction(Transaction txn)
Sets default transaction to use in case that null parameter is used as transaction parameter with JavaSpace methods. |
void |
setFifo(boolean enabled)
Sets FIFO mode for proxy. |
void |
setNOWriteLeaseMode(boolean noWriteLeaseMode)
If set to true , Lease object will not return from
write /writeMultiple operations. |
void |
setOptimisticLocking(boolean enabled)
Enable/Disable Optimistic Lock protocol. |
int |
setReadTakeModifiers(int newModifiers)
Sets the read-take mode modifiers for proxy level. |
void |
setSecurityContext(SecurityContext sc)
This function is called by the client (usually at the beginning of the session) in order to set a security context for the following operations. |
int |
setUpdateModifiers(int newModifiers)
Sets the update mode modifiers for proxy level. |
Object |
snapshot(Object object)
The process of serializing an entry for transmission to a JavaSpaces service will be identical if the same entry is used twice. |
Object |
take(Object object,
Transaction transaction,
long timeout)
Take any matching entry from the space, blocking until one exists. |
Object |
takeIfExists(Object object,
Transaction transaction,
long timeout)
Take if exists any matching entry from the space, blocking until one exists. |
Entry[] |
takeMultiple(Entry template,
Transaction txn,
int maxEntries)
Takes all the entries matching the specified template from this space. |
Object[] |
takeMultiple(Object template,
Transaction txn,
int maxEntries)
Takes all the entries matching the specified template from this space. |
Object[] |
update(Entry template,
Entry newEntry,
Transaction txn,
long lease)
Deprecated. use instead: update(Entry, Transaction, long, long, int) |
Entry |
update(Entry template,
Entry updatedEntry,
Transaction transaction,
long lease,
long timeout)
Deprecated. use instead: update(Entry, Transaction, long, long, int) |
Entry |
update(Entry updatedEntry,
Transaction transaction,
long lease,
long timeout)
Equivalent to calling update(Entry, Transaction, long, long, int) with
modifiers (if any) set by setUpdateModifiers(int) . |
Entry |
update(Entry updatedEntry,
Transaction transaction,
long lease,
long timeout,
boolean writeIfAbsent)
Deprecated. use instead update(Entry, Transaction, long, long, int) with
UpdateModifiers.UPDATE_OR_WRITE modifier which is equivalent to setting
writeIfAbsent=true . |
Entry |
update(Entry updatedEntry,
Transaction transaction,
long lease,
long timeout,
int updateModifiers)
Equivalent to calling update(Object, Transaction, long, long, int) by use of
a cast from Entry to Object. see it also as a reference to further semantics of this method. |
Object |
update(Object updatedEntry,
Transaction transaction,
long lease,
long timeout)
Equivalent to calling update(Object, Transaction, long, long, int) with
modifiers (if any) set by setUpdateModifiers(int) . |
Object |
update(Object updatedEntry,
Transaction transaction,
long lease,
long timeout,
int updateModifiers)
An update operation against a space entity which it's UID is known, blocking if locked under another transaction. |
Object[] |
updateMultiple(Entry[] entries,
Transaction transaction,
long[] leases)
Equivalent to calling updateMultiple(Entry[], Transaction, long[], int) with
modifiers (if any) set by setUpdateModifiers(int) . |
Object[] |
updateMultiple(Entry[] entries,
Transaction transaction,
long[] leases,
int updateModifiers)
Equivalent to calling updateMultiple(Object[], Transaction, long[], int) by use of an
array of Object[] constructed as new Entry[]. see it also as a reference
to further semantics of this method. |
Object[] |
updateMultiple(Object[] entries,
Transaction transaction,
long[] leases)
Equivalent to calling updateMultiple(Object[], Transaction, long[], int) with
modifiers (if any) set by setUpdateModifiers(int) . |
Object[] |
updateMultiple(Object[] objects,
Transaction transaction,
long[] leases,
int updateModifiers)
Same as a single update but for a group of entities sharing the same transaction (if any), applied with the same operation modifier (or default Modifiers.NONE ). |
LeaseContext |
write(Object object,
Transaction transaction,
long lease)
Equivalent to calling write(Object, Transaction, long, long, int) with the
UpdateModifiers.UPDATE_OR_WRITE . |
LeaseContext |
write(Object object,
Transaction transaction,
long lease,
long timeout,
int modifiers)
Writes a new object to the space, returning its Lease . |
Lease[] |
writeMultiple(Entry[] entries,
Transaction txn,
long lease)
Writes the specified entries to this space. |
Lease[] |
writeMultiple(Object[] objects,
Transaction txn,
long lease)
Writes the specified objects to this space. |
Methods inherited from interface net.jini.space.JavaSpace |
---|
notify, read, readIfExists, snapshot, take, takeIfExists, write |
Method Detail |
---|
String getName()
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/")
;
String name = aSpace.getName();
void clean() throws RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
aSpace.clean();
RemoteException
- if a communication error occursObject getAdmin() throws RemoteException
// get a list of classes and the number of entries of each class
IRemoteJSpaceAdmin
spaceAdmin = (IRemoteJSpaceAdmin)space.getAdmin();
Object classList[] = spaceAdmin.getRuntimeInfo().m_ClassNames.toArray();
List numOFEntries = spaceAdmin.getRuntimeInfo().m_NumOFEntries;
RemoteException
- if a communication error occursvoid ping() throws RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
try{
aSpace.ping();
System.out.println("Space alive");
}
catch (java.rmi.RemoteException re) {
System.out.println("Space unreachable");
}
RemoteException
- when space was unreachableObject[] replace(Entry template, Entry newEntry, Transaction txn, long lease) throws TransactionException, UnusableEntryException, RemoteException
update(Entry, Transaction, long, long, int)
IJSpace aSpace = (IJSpace)
The replace method is not atomic (unless used with transaction) which means that the former call equals to:SpaceFinder.find("jini://lookup-host/container-name/space-name")
; Message tmpl = new Message("Hello World"); Message msg = new Message("Goodbye World"); Object[] result = aSpace.replace(tmpl, msg, null, Lease.FOREVER); Message old = (Message)result[0]; long msgLease = ((Lease)result[1]).getExpiration();Message old = (Message)aSpace.take(tmpl, null,
JavaSpace.NO_WAIT
); Lease lease = aSpace.write(msg, null,Lease.FOREVER
);
template
- the template to use for matching.newEntry
- the value of the new entry.txn
- the transaction under which to perform the operation.lease
- the lease time of the new entry
null
is returned.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occurs
IllegalArgumentException
- if the lease time requested is not Lease.ANY and is negativeupdate(Entry, Entry, Transaction, long)
Object update(Object updatedEntry, Transaction transaction, long lease, long timeout) throws TransactionException, UnusableEntryException, RemoteException, InterruptedException
update(Object, Transaction, long, long, int)
with
modifiers (if any) set by setUpdateModifiers(int)
.
updatedEntry
- the new value of the entry, must contain the UID.transaction
- The transaction under which to perform the operation.lease
- The lease time of the updated entry, 0 means retain the original leasetimeout
- "IfExists" timeout
update(Object, Transaction, long, long, int)
according to
the set UpdateModifier
. (see setUpdateModifiers(int)
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occurs
InterruptedException
- if the thread in which the read occurs is interrupted
IllegalArgumentException
- if the lease time requested
is not Lease.ANY and is negativeupdate(Object, Transaction, long, long, int)
,
UpdateModifiers
,
setUpdateModifiers(int)
Object update(Object updatedEntry, Transaction transaction, long lease, long timeout, int updateModifiers) throws TransactionException, UnusableEntryException, RemoteException, InterruptedException
IMetaDataEntry
or having one of the UID access
methods:
public void __setEntryUID(String inUid)
public String __getEntryUID()
An update can be performed, with any of the modifiers listed in
UpdateModifiers
,
UpdateModifiers.UPDATE_ONLY
- pure update operation, UpdateModifiers.UPDATE_OR_WRITE
- writes if absent or updates
existing, UpdateModifiers.PARTIAL_UPDATE
- updates only non-null fields
Transactions:
An update lock guarantees that you are the sole holder of a space entity.
An update lock blocks all other requests for a read, take or update on
this particular entity. An update will be blocked until timeout expires,
returning a null result or until the lock has been released and acquired
by this call.
Optimistic Locking:
With optimistic locking set, an update operation has a chance of
failing (throwing EntryVersionConflictException
) if it was
performed on an obsolete copy. To enable Optimistic Locking with update,
set setOptimisticLocking(boolean)
.
Sample code:
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Message msg = new Message("Hello");
Lease lease = aSpace.write(msg, null, Lease.FOREVER);
LeaseProxy
lp = (LeaseProxy)lease;
String uid = lp.getUID();
Message upde = new Message("Hello World");
upde.__setEntryUID(uid);
Object result = aSpace.update(upde, null, Lease.FOREVER, 60000, UpdateModifiers.UPDATE_OR_WRITE);
updatedEntry
- The new value of the entity, where matching is done by UID.transaction
- The transaction (if any) under which to work.lease
- The requested lease time of the updated entity, in milliseconds; 0 means retain the original lease.timeout
- How long the client is willing to wait for a transactionally proper matching entity.
A timeout of NO_WAIT means to wait no time at all; this is equivalent to a wait of zero.updateModifiers
- operation modifiers, values from UpdateModifiers
null
- if timeout occurred after waiting for a transactional proper matching entry.
UpdateModifiers.UPDATE_OR_WRITE
modifier is applied,
null
- if write was successful,
EntryNotInSpaceException
- if an entry with such a UID doesn't exits in the space
OperationTimeoutException
- if timeout expires (when used with
UpdateModifiers.UPDATE_OR_WRITE
modifier)
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
or EntryNotInSpaceException
is throw when the UId is not exists in the space
RemoteException
- if a communication error occurs
InterruptedException
- if the thread in which the read occurs is interrupted
IllegalArgumentException
- if the lease time requested
is not Lease.ANY and is negativeUpdateModifiers
,
IMetaDataEntry
Object[] updateMultiple(Object[] entries, Transaction transaction, long[] leases) throws UnusableEntryException, TransactionException, RemoteException
updateMultiple(Object[], Transaction, long[], int)
with
modifiers (if any) set by setUpdateModifiers(int)
.
entries
- the array of entries containing the new values , each entry
must contain its UID.transaction
- The transaction under which to perform the operation.leases
- The lease time of the updated entries, 0 means retain the
original lease
updateMultiple(Object[], Transaction, long[], int)
according to
the set UpdateModifiers
. (see setUpdateModifiers(int)
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being
read cannot be deserialized for any reason
RemoteException
- if a communication error occursvoid setSecurityContext(SecurityContext sc) throws SpaceSecurityException, RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
SecurityContext sc = new SecurityContext("anonymous", "anonymous");
aSpace.setSecurityContext(sc);
sc
- the SecurityContext to be active (or null to disable).
SpaceSecurityException
- Thrown by the Space or Filter to indicate a security violation.
RemoteException
- if a communication error occursboolean isSecured()
DefaultSecurityFilter
void dropClass(String className) throws RemoteException, DropClassException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Message msg = new Message("Hello");
Lease lease = aSpace.write(msg, null, Lease.FOREVER);
aSpace.dropClass( Message.class.getName());
className
- name of class to delete.
DropClassException
- Failed to drop desired class.
RemoteException
- if a communication error occursclear(Entry, Transaction)
boolean isEmbedded()
true
if the proxy embedded, otherwise false
.void setOptimisticLocking(boolean enabled)
enabled
- true
enable Optimistic Lock protocol,
false
disable.IMetaDataEntry
boolean isOptimisticLockingEnabled()
true
Optimistic Lock enabled, otherwise false
.IMetaDataEntry
void setFifo(boolean enabled)
SpaceFinder.find("jini://localhost/myContainerName/JavaSpaces?fifo=true")
If this mode enabled, you don't need to use com.j_spaces.core.client.MetaDataEntry.setFifo(boolean)
for every entry/template. All entries and templates will be FIFO enabled.
enabled
- if true
this proxy FIFO enabled, otherwise false
.IMetaDataEntry
boolean isFifo()
true
if this proxy FIFO enabled, otherwise false
.
true
if this proxy FIFO enabled, otherwise false
.IMetaDataEntry
void setNOWriteLeaseMode(boolean noWriteLeaseMode)
true
, Lease
object will not return from
write
/writeMultiple
operations.
SpaceFinder
:
SpaceFinder.find("jini://localhost/myContainerName/JavaSpaces?noWriteLease")
noWriteLeaseMode
- write mode.SpaceURL
boolean isNOWriteLeaseMode()
true
if do not return Lease object after write, otherwise false
.setNOWriteLeaseMode(boolean)
IStubHandler getStubHandler()
Uuid getReferentUuid()
ReferentUuid
void setDefaultTransaction(Transaction txn)
null
otherwise the TransactionException
will be thrown on the next space operation call.
space.setDefaultTransaction( txn);
space.write( entry1, null, Lease.FOREVER );
space.write( entry2, null, Lease.FOREVER );
txn.commit();
space.setDefaultTransaction( null);
Note: This function is unsupported when using it in conjunction with local cache.
txn
- the default transaction.IJSpaceContainer getContainer()
SpaceURL getURL()
SpaceURL
instance which was used to initialize the space.
Notice: The SpaceURL
object contains information on the space and container
configuration/setup such as space url used, space/container/cluster schema used
and other attributes.
The IJSpaceContainer
keeps also its reference of the SpaceURL which launched the container.
SpaceURL
which initialized that specific space instance.int setUpdateModifiers(int newModifiers)
newModifiers
- new values for modifiers
Values are defined in
UpdateModifiers
.
old value
of modifiers.int getUpdateModifiers()
UpdateModifiers
class.
UPDATE_ONLY
.
value
of modifiers.int setReadTakeModifiers(int newModifiers)
newModifiers
- new values for modifiers
Values are defined in ReadTakeModifiers
.
old value
of modifiers.int getReadTakeModifiers()
ReadTakeModifiers
.
value
of modifiers.EventRegistration notify(Object object, Transaction transaction, RemoteEventListener remoteeventlistener, long lease, MarshalledObject marshalledobject) throws TransactionException, RemoteException
object
- The template used for matching. Matching is done using a
template with null fields resulting in wildcards ("match anything") other
fields resulting in values ("match exactly on the serialized form").transaction
- The transaction (if any) under which to work.remoteeventlistener
- The remote event listener to notify.lease
- the requested lease time, in millisecondsmarshalledobject
- An object to send to the listener as part of the
event notification
TransactionException
RemoteException
Object snapshot(Object object) throws RemoteException
object
- the object to take a snapshot of.
RemoteException
- - if a communication error occursEventRegistration notify(Object template, Transaction txn, RemoteEventListener listener, long lease, MarshalledObject handback, int modifiers) throws TransactionException, RemoteException
JavaSpace.notify()
method.NOTIFY_ALL
,
or use specific types:
Available Notify types:
NotifyModifiers.NOTIFY_WRITE
NotifyModifiers.NOTIFY_UPDATE
NotifyModifiers.NOTIFY_TAKE
NotifyModifiers.NOTIFY_LEASE_EXPIRATION
NotifyModifiers.NOTIFY_ALL
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Message template = new Message();
EventRegistration eventReg = aSpace.notify( template, null, this, Lease.FOREVER, null, NotifyModifiers.NOTIFY_ALL);
System.out.println("Notification registered. Registration id: "
+ eventReg.getID() + " ; Sequence number: "
+ eventReg.getSequenceNumber());
Note: the RemoteEventListner identifier has been passed as this
, indicating
that the current class implements RemoteEventListener. notify
method. You could then obtain
the entry that triggered the event e.g.:
void notify(RemoteEvent theEvent) {
...
EntryArrivedRemoteEvent
arrivedRemoteEvent = (EntryArrivedRemoteEvent)theEvent;
Object entry = arrivedRemoteEvent.getObject();
int notifyType = arrivedRemoteEvent.getNotifyType();
...
}
template
- The template used for matching. Matching is done using a
template with null fields resulting in wildcards ("match anything") other
fields resulting in 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.modifiers
- the modifiers.
TransactionException
- if a transaction error occurs
RemoteException
- if a communication error occurs
IllegalArgumentException
- if the lease time requested
is not Lease.ANY and is negativeJavaSpace.notify(Entry, Transaction, RemoteEventListener, long, MarshalledObject)
,
NotifyModifiers
,
NotifyDelegator
Object[] takeMultiple(Object template, Transaction txn, int maxEntries) throws TransactionException, UnusableEntryException, RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Object
multiTmpl = new Message();
Object[] results = aSpace.takeMultiple( multiTmpl, null, Integer.MAX_VALUE );
for (int i=0; i<results.length; i++)
{
System.out.println("Taken-Multiple: "+((Message)results[i]).content);
}
template
- the template to use for matching.txn
- the transaction under which to perform the operation.maxEntries
- a limit on the number of entries to be taken. Use
Integer.MAX_VALUE
for the maximum value.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursObject read(Object entry, Transaction transaction, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException
entry
- The template used for matching.
Matching is done against template with null fields being wildcards ("match anything")
other fields being values ("match exactly on the serialized form").transaction
- the transaction object, if any, under which to perform
the write
lease the requested lease time, in millisecondstimeout
- How long the client is willing to wait for a
transactionally proper matching entry. A timeout of NO_WAIT
means to wait no time at all; this is equivalent to a wait of
zero.
UnusableEntryException
TransactionException
- - if a transaction error
occurs,RemoteException - if a communication error occurs
InterruptedException
RemoteException
Object readIfExists(Object object, Transaction transaction, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException
object
- The template used for matching. Matching is done against
template with null fields being wildcards ("match anything") other
fields being values ("match exactly on the serialized form").transaction
- The template used for matching. Matching is done
against template with null fields being wildcards ("match
anything") other fields being values ("match exactly on the
serialized form").timeout
- How long the client is willing to wait for a
transactionally proper matching entry. A timeout of NO_WAIT
means to wait no time at all; this is equivalent to a wait of
zero.
UnusableEntryException
- - if any serialized field of the entry
being read cannot be deserialized for any reason
TransactionException - if a transaction error occurs
InterruptedException - if the thread in which the read occurs
is interrupted RemoteException - if a communication error
occurs IllegalArgumentException - if a negative timeout value
is used
TransactionException
InterruptedException
RemoteException
Object take(Object object, Transaction transaction, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException
object
- The template used for matching. Matching is done against
tmpl with null fields being wildcards ("match anything") other
fields being values ("match exactly on the serialized form").transaction
- The template used for matching. Matching is done
against tmpl with null fields being wildcards ("match
anything") other fields being values ("match exactly on the
serialized form").timeout
- How long the client is willing to wait for a
transactionally proper matching entry. A timeout of NO_WAIT
means to wait no time at all; this is equivalent to a wait of
zero.
UnusableEntryException
- - if any serialized field of the entry
being read cannot be deserialized for any reason
TransactionException - if a transaction error occurs
InterruptedException - if the thread in which the read occurs
is interrupted RemoteException - if a communication error
occurs IllegalArgumentException - if a negative timeout value
is used
TransactionException
InterruptedException
RemoteException
Object takeIfExists(Object object, Transaction transaction, long timeout) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException
object
- The template used for matching. Matching is done against
tmpl with null fields being wildcards ("match anything") other
fields being values ("match exactly on the serialized form").transaction
- The template used for matching. Matching is done
against tmpl with null fields being wildcards ("match
anything") other fields being values ("match exactly on the
serialized form").timeout
- How long the client is willing to wait for a
transactionally proper matching entry. A timeout of NO_WAIT
means to wait no time at all; this is equivalent to a wait of
zero.
UnusableEntryException
- - if any serialized field of the entry
being read cannot be deserialized for any reason
TransactionException - if a transaction error occurs
InterruptedException - if the thread in which the read occurs
is interrupted RemoteException - if a communication error
occurs IllegalArgumentException - if a negative timeout value
is used
TransactionException
InterruptedException
RemoteException
void clear(Object template, Transaction txn) throws RemoteException, TransactionException, UnusableEntryException
IJSpace aSpace = (IJSpace)
If the clear operation conducted without transaction (null as value) it will clear all entries that are not under transaction. Therefor entries under transaction would not be removed from the space. The clear operation supports inheritance, therefore template class matching objects and its sub classes matching objects are part of the candidates population that will be from the space. You can in fact clean all space objects (that are not under transaction) by calling:SpaceFinder.find("jini://lookup-host/container-name/space-name")
; Object multiTmpl = new Message(); aSpace.clear(multiTmpl, null);space.clear( null, null)
. Notice: The clear operation does not remove notify templates i.e. registration for notifications.
template
- the template to use for matching.txn
- the transaction under which to perform the operation.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be de serialized for any reason
RemoteException
- if a communication error occursclean()
int count(Object template, Transaction txn) throws RemoteException, TransactionException, UnusableEntryException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Object multiTmpl = new Message();
int counted = aSpace.count(multiTmpl, null);
System.out.println("There are " + counted + " matches in the space");
template
- the template to use for matching.txn
- the transaction under which to perform the operation.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursLease[] writeMultiple(Object[] objects, Transaction txn, long lease) throws TransactionException, RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Object
[] objects = new Object[100];
for (int i=0; i<objects.length; i++)
{
objects[i] = new Message("Hello World -"+i);
}
aSpace.writeMultiple( objects, null, Lease.FOREVER );
objects
- the objects to write.txn
- the transaction object, if any, under which to perform the writelease
- the requested lease time, in milliseconds
TransactionException
- if a transaction error occurs
RemoteException
- if a communication error occurs
IllegalArgumentException
- if the lease time requested
is not Lease.ANY and is negativeObject[] readMultiple(Object template, Transaction txn, int maxEntries) throws TransactionException, UnusableEntryException, RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Object
multiTmpl = new Message();
Object[] results = aSpace.readMultiple( multiTmpl, null, Integer.MAX_VALUE );
for (int i=0; i<results.length; i++)
{
System.out.println("Read-Multiple: "+((Message)results[i]).content);
}
template
- the template to use for matching.txn
- the transaction under which to perform the operation.maxEntries
- a limit on the number of objects to be read. Use
Integer.MAX_VALUE
for the maximum value.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursLeaseContext write(Object object, Transaction transaction, long lease) throws TransactionException, RemoteException
write(Object, Transaction, long, long, int)
with the
UpdateModifiers.UPDATE_OR_WRITE
.
object
- the object to writetransaction
- the transaction object, if any, under which to perform
the writelease
- the requested lease time, in milliseconds
Lease
on a successful write, or null
if performed with NoWriteLease attribute.
when UpdateModifiers.UPDATE_OR_WRITE
modifier is applied,
LeaseContext.getObject()
returns:
EntryAlreadyInSpaceException
- if an entry with the same UID already exists in space (Modifiers.WRITE
)
EntryNotInSpaceException
- if an entry with such a UID doesn't exits in the space (Modifiers.UPDATE
)
TransactionException
- if a transaction error occurs
RemoteException
- if a communication error occursLeaseContext write(Object object, Transaction transaction, long lease, long timeout, int modifiers) throws TransactionException, RemoteException
Lease
.
Applying the UpdateModifiers.UPDATE_OR_WRITE
modifier, is
equivalent to calling
update(Object, Transaction, long, long, int)
, but otherwise
returning a Lease on a successful write.
If the object has a primary key,isn't auto - generated, and the modifiers value is one of
UpdateModifiers.UPDATE_OR_WRITE
,UpdateModifiers.UPDATE_ONLY
or
UpdateModifiers.PARTIAL_UPDATE
, it will call to the update method, returning a
LeaseContext holder. This lease is unknown to the grantor, unless an actual 'write' was performed.
The operation can also be forced to perfom write operation using the
UpdateModifiers.WRITE_ONLY
resulting in an
EntryAlreadyInSpaceException
exception if the object
already exists in the space.
transaction
- the transaction object, if any, under which to perform the writeobject
- the object to writelease
- the requested lease time, in millisecondstimeout
- modifiers
-
Lease
on a successful write, or null
if performed with NoWriteLease attribute.
when UpdateModifiers.UPDATE_OR_WRITE
modifier is applied,
LeaseContext.getObject()
returns:
EntryAlreadyInSpaceException
- if an entry with the same UID already exists in space (Modifiers.WRITE
)
EntryNotInSpaceException
- if an entry with such a UID doesn't exits in the space (Modifiers.UPDATE
)
OperationTimeoutException
- if timeout expires (when used
with UpdateModifiers.UPDATE_OR_WRITE
modifier)
TransactionException
- if a transaction error occurs
RemoteException
- if a communication error occursObject[] updateMultiple(Object[] objects, Transaction transaction, long[] leases, int updateModifiers) throws UnusableEntryException, TransactionException, RemoteException
Modifiers.NONE
).
The semantics of a single update and a batch update are similar - the return
value for each corresponds to it's cell in the returned array.
see 'returns'
for possible return values.
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Lease[] leases = ...//see writeMultiple
Object[] results = aSpace.readMultiple( multiTmpl, null, Integer.MAX_VALUE );
for (int i=0; i<results.length; i++)
{
// modify entry Object by adding an index to the content
((Message)results[i]).content += i;
}
// updates the space with the modified entries
Object[] results = aSpace.updateMultiple(results, null, leases);
objects
- the array of objects containing the new values,
each entry must contain its UID.transaction
- The transaction under which to perform the operation.leases
- The lease time of the updated objects, 0 means retain the original leaseupdateModifiers
- operation modifiers, values from UpdateModifiers
null
- if timeout occurred after waiting for a transactional proper matching entry
UpdateModifiers.UPDATE_OR_WRITE
modifier is applied,
null
- if write was successful,
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursvoid clear(Entry template, Transaction txn) throws RemoteException, TransactionException, UnusableEntryException
IJSpace aSpace = (IJSpace)
If the clear operation conducted without transaction (null as value) it will clear all entries that are not under transaction. Therefor entries under transaction would not be removed from the space. The clear operation supports inheritance, therefor template class matching objects and its sub classes matching objects are part of the candidates population to be removed from the space. You can in fact clean all space objects (that are not under transaction) by calling:SpaceFinder.find("jini://lookup-host/container-name/space-name")
; Entry multiTmpl = new Message(); aSpace.clear(multiTmpl, null);space.clear( null, null)
. Notice: The clear operation does not remove notify templates i.e. registration for notifications.
template
- the template to use for matching.txn
- the transaction under which to perform the operation.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursclean()
int count(Entry template, Transaction txn) throws RemoteException, TransactionException, UnusableEntryException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Entry multiTmpl = new Message();
int counted = aSpace.count(multiTmpl, null);
System.out.println("There are " + counted + " matches in the space");
template
- the template to use for matching.txn
- the transaction under which to perform the operation.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursEventRegistration notify(Entry template, Transaction txn, RemoteEventListener listener, long lease, MarshalledObject handback, int notifyType) throws TransactionException, RemoteException
JavaSpace.notify()
method.NOTIFY_ALL
,
or use specific types:
Available Notify types:
NotifyModifiers.NOTIFY_WRITE
NotifyModifiers.NOTIFY_UPDATE
NotifyModifiers.NOTIFY_TAKE
NotifyModifiers.NOTIFY_LEASE_EXPIRATION
NotifyModifiers.NOTIFY_ALL
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Entry template = new Message();
EventRegistration eventReg = aSpace.notify( template, null, this, Lease.FOREVER, null, NotifyModifiers.NOTIFY_ALL);
System.out.println("Notification registered. Registration id: "
+ eventReg.getID() + " ; Sequence number: "
+ eventReg.getSequenceNumber());
Note: the RemoteEventListner identifier has been passed as this
, indicating
that the current class implements RemoteEventListener. notify
method. You could then obtain
the entry that triggered the event e.g.:
void notify(RemoteEvent theEvent) {
...
EntryArrivedRemoteEvent
arrivedRemoteEvent = (EntryArrivedRemoteEvent)theEvent;
Entry entry = arrivedRemoteEvent.getEntry();
int notifyType = arrivedRemoteEvent.getNotifyType();
...
}
template
- The template used for matching. Matching is
done against template
with null
fields 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.notifyType
- Notify type.
TransactionException
- if a transaction error occurs
RemoteException
- if a communication error occurs
IllegalArgumentException
- if the lease time requested
is not Lease.ANY and is negativeJavaSpace.read(Entry, Transaction, long)
,
NotifyModifiers
,
NotifyDelegator
Entry[] readMultiple(Entry template, Transaction txn, int maxEntries) throws TransactionException, UnusableEntryException, RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Entry
multiTmpl = new Message();
Entry[] results = aSpace.readMultiple( multiTmpl, null, Integer.MAX_VALUE );
for (int i=0; i<results.length; i++)
{
System.out.println("Read-Multiple: "+((Message)results[i]).content);
}
template
- the template to use for matching.txn
- the transaction under which to perform the operation.maxEntries
- a limit on the number of entries to be read. Use
Integer.MAX_VALUE
for the maximum value.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursEntry[] takeMultiple(Entry template, Transaction txn, int maxEntries) throws TransactionException, UnusableEntryException, RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Entry
multiTmpl = new Message();
Entry[] results = aSpace.takeMultiple( multiTmpl, null, Integer.MAX_VALUE );
for (int i=0; i<results.length; i++)
{
System.out.println("Taken-Multiple: "+((Message)results[i]).content);
}
template
- the template to use for matching.txn
- the transaction under which to perform the operation.maxEntries
- a limit on the number of entries to be taken. Use
Integer.MAX_VALUE
for the maximum value.
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occurs@Deprecated Object[] update(Entry template, Entry newEntry, Transaction txn, long lease) throws TransactionException, UnusableEntryException, RemoteException
update(Entry, Transaction, long, long, int)
TransactionException
UnusableEntryException
RemoteException
@Deprecated Entry update(Entry template, Entry updatedEntry, Transaction transaction, long lease, long timeout) throws TransactionException, UnusableEntryException, RemoteException, InterruptedException
update(Entry, Transaction, long, long, int)
TransactionException
UnusableEntryException
RemoteException
InterruptedException
Entry update(Entry updatedEntry, Transaction transaction, long lease, long timeout) throws TransactionException, UnusableEntryException, RemoteException, InterruptedException
update(Entry, Transaction, long, long, int)
with
modifiers (if any) set by setUpdateModifiers(int)
.
updatedEntry
- the new value of the entry, must contain the UID.transaction
- The transaction under which to perform the operation.lease
- The lease time of the updated entry, 0 means retain the original leasetimeout
- "IfExists" timeout
update(Entry, Transaction, long, long, int)
according to
the set UpdateModifiers
. (see setUpdateModifiers(int)
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occurs
InterruptedException
- if the thread in which the read occurs is interrupted
IllegalArgumentException
- if the lease time requested
is not Lease.ANY and is negativeupdate(Entry, Transaction, long, long, int)
,
UpdateModifiers
,
setUpdateModifiers(int)
@Deprecated Entry update(Entry updatedEntry, Transaction transaction, long lease, long timeout, boolean writeIfAbsent) throws TransactionException, UnusableEntryException, RemoteException, InterruptedException
update(Entry, Transaction, long, long, int)
with
UpdateModifiers.UPDATE_OR_WRITE
modifier which is equivalent to setting
writeIfAbsent=true
.
TransactionException
UnusableEntryException
RemoteException
InterruptedException
Object[] updateMultiple(Entry[] entries, Transaction transaction, long[] leases) throws UnusableEntryException, TransactionException, RemoteException
updateMultiple(Entry[], Transaction, long[], int)
with
modifiers (if any) set by setUpdateModifiers(int)
.
entries
- the array of entries containing the new values ,
each entry must contain its UID.transaction
- The transaction under which to perform the operation.leases
- The lease time of the updated entries, 0 means retain the original lease
updateMultiple(Entry[], Transaction, long[], int)
according to
the set UpdateModifiers
. (see setUpdateModifiers(int)
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursObject[] updateMultiple(Entry[] entries, Transaction transaction, long[] leases, int updateModifiers) throws UnusableEntryException, TransactionException, RemoteException
updateMultiple(Object[], Transaction, long[], int)
by use of an
array of Object[] constructed as new Entry[]. see it also as a reference
to further semantics of this method.
Object[] entries = new Entry[length];
Lease[] leases = new Lease[length];
for (int i=0; i<length; i++)
{
entries[i] = new Message("hello-"+i);
leases[i] = Lease.FOREVER;
}
Object[] results = aSpace.updateMultiple(entries, null, leases, UpdateModifiers.UPDATE_ONLY
);
entries
- the array of entries containing the new values ,
each entry must contain its UID.transaction
- The transaction under which to perform the operation.leases
- The lease time of the updated entries, 0 means retain the original leaseupdateModifiers
- operation modifiers, values from UpdateModifiers
null
- if timeout occurred after waiting for a transactional proper matching entry
UpdateModifiers.UPDATE_OR_WRITE
modifier is applied,
null
- if write was successful,
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
RemoteException
- if a communication error occursLease[] writeMultiple(Entry[] entries, Transaction txn, long lease) throws TransactionException, RemoteException
IJSpace aSpace = (IJSpace)SpaceFinder.find("jini://lookup-host/container-name/space-name")
;
Entry
[] entries = new Entry[100];
for (int i=0; i<entries.length; i++)
{
entries[i] = new Message("Hello World -"+i);
}
aSpace.writeMultiple( entries, null, Lease.FOREVER );
entries
- the entries to write.txn
- the transaction object, if any, under which to perform the writelease
- the requested lease time, in milliseconds
TransactionException
- if a transaction error occurs
RemoteException
- if a communication error occurs
IllegalArgumentException
- if the lease time requested
is not Lease.ANY and is negativeEntry update(Entry updatedEntry, Transaction transaction, long lease, long timeout, int updateModifiers) throws TransactionException, UnusableEntryException, RemoteException, InterruptedException
update(Object, Transaction, long, long, int)
by use of
a cast from Entry to Object. see it also as a reference to further semantics of this method.
updatedEntry
- The new value of the entry, where matching is done by UID.transaction
- The transaction (if any) under which to work.lease
- The requested lease time of the updated entry, in milliseconds; 0 means retain the original lease.timeout
- How long the client is willing to wait for a transactionally proper matching entry. A timeout of NO_WAIT means to wait no time at all; this is equivalent to a wait of zero.updateModifiers
- operation modifiers, values from UpdateModifiers
null
- if timeout occurred after waiting for a transactional proper matching entry.
UpdateModifiers.UPDATE_OR_WRITE
modifier is applied,
null
- if write was successful,
EntryNotInSpaceException
- if an entry with such a UID doesn't exits in the space
OperationTimeoutException
- if timeout expires (when used
with UpdateModifiers.UPDATE_OR_WRITE
modifier)
TransactionException
- if a transaction error occurs
UnusableEntryException
- if any serialized field of the entry being read cannot be deserialized for any reason
or EntryNotInSpaceException
is throw when the UId is not exists in the space
RemoteException
- if a communication error occurs
InterruptedException
- if the thread in which the read occurs is interrupted
IllegalArgumentException
- if the lease time requested
is not Lease.ANY and is negativeupdate(Object, Transaction, long, long, int)
,
UpdateModifiers
,
setUpdateModifiers(int)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |