com.sun.sgs.impl.service.data.store.net
Class DataStoreServerImpl

java.lang.Object
  extended by com.sun.sgs.impl.service.data.store.net.DataStoreServerImpl
All Implemented Interfaces:
DataStoreServer, Remote

public class DataStoreServerImpl
extends Object
implements DataStoreServer

Provides an implementation of DataStoreServer, using the DataStoreImpl class to support the same database format which that class supports.

In addition to those supported by the DataStoreImpl class, the constructor supports the following properties:

Property: com.sun.sgs.impl.service.data.store.net.max.txn.timeout
Default: 600000
The maximum amount of time in milliseconds that a transaction will be permitted to run before it is a candidate for being aborted.

Property: com.sun.sgs.impl.service.data.store.net.server.reap.delay
Default: 500
The delay in milliseconds between attempts to reap timed out transactions.

Property: com.sun.sgs.impl.service.data.store.net.server.port
Default: 44530
The network port for running the server. This value must be greater than or equal to 0 and no greater than 65535. If the value specified is 0, then an anonymous port will be chosen. The value chosen will be logged, and can also be accessed with the getPort method.

In addition to any logging performed by the DataStoreImpl class, this class uses the Logger named com.sun.sgs.impl.service.data.store.net.server to log information at the following levels:


Field Summary
(package private) static LoggerWrapper logger
          The logger for this class.
(package private)  com.sun.sgs.impl.service.data.store.net.DataStoreServerImpl.TxnTable<?> txnTable
          Stores information about transactions.
 
Constructor Summary
DataStoreServerImpl(Properties properties, ComponentRegistry systemRegistry, TransactionProxy txnProxy)
          Creates an instance of this class configured with the specified properties.
 
Method Summary
 void abort(long tid)
          Aborts the transaction.
 void commit(long tid)
          Commits the transaction.
 long createObject(long tid)
          Reserves an object ID for a new object.
 long createTransaction(long timeout)
          Creates a new transaction, and returns the associated ID, which will not be negative.
 BindingValue getBinding(long tid, String name)
          Obtains the object ID bound to a name.
 int getClassId(long tid, byte[] classInfo)
          Returns the class ID to represent classes with the specified class information.
 byte[] getClassInfo(long tid, int classId)
          Returns the class information associated with the specified class ID.
 byte[] getObject(long tid, long oid, boolean forUpdate)
          Obtains the data associated with an object ID.
 int getPort()
          Returns the port being used for the server.
 void markForUpdate(long tid, long oid)
          Notifies the server that an object is going to be modified.
 long newNodeId()
          Returns a new node ID for use with a newly started node.
 String nextBoundName(long tid, String name)
          Returns the next name after the specified name that has a binding, or null if there are no more bound names.
 long nextObjectId(long tid, long oid)
          Returns the object ID for the next object after the object with the specified ID, or -1 if there are no more objects.
 boolean prepare(long tid)
          Prepares the transaction to commit.
 void prepareAndCommit(long tid)
          Prepares and commits the transaction.
(package private)  void reapExpiredTransactions()
          Find transactions that are expired and not in use, and tell the data store to abort them.
 BindingValue removeBinding(long tid, String name)
          Removes the binding for a name.
 void removeObject(long tid, long oid)
          Removes the object with the specified object ID.
 BindingValue setBinding(long tid, String name, long oid)
          Binds an object ID to a name.
 void setObject(long tid, long oid, byte[] data)
          Specifies data to associate with an object ID.
 void setObjects(long tid, long[] oids, byte[][] dataArray)
          Specifies data to associate with a series of object IDs.
 void shutdown()
          Shuts down this server.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

static final LoggerWrapper logger
The logger for this class.


txnTable

com.sun.sgs.impl.service.data.store.net.DataStoreServerImpl.TxnTable<?> txnTable
Stores information about transactions.

Constructor Detail

DataStoreServerImpl

public DataStoreServerImpl(Properties properties,
                           ComponentRegistry systemRegistry,
                           TransactionProxy txnProxy)
                    throws IOException
Creates an instance of this class configured with the specified properties. See the class documentation for a list of supported properties.

Parameters:
properties - the properties for configuring this instance
systemRegistry - the registry of available system components
txnProxy - the transaction proxy
Throws:
DataStoreException - if there is a problem with the database
IllegalArgumentException - if the value of the com.sun.sgs.impl.service.data.store.net.DataStoreServerImpl.port property is less than 0 or greater than 65535, or if thrown by the DataStoreImpl constructor
IOException - if a network problem occurs
Method Detail

newNodeId

public long newNodeId()
Returns a new node ID for use with a newly started node.

Specified by:
newNodeId in interface DataStoreServer
Returns:
the new node ID

createObject

public long createObject(long tid)
Reserves an object ID for a new object. Note that calling other operations using this ID are not required to find the objects until setObject is called. Aborting a transaction is also not required to unassign any of the IDs so long as other operations treat them as non-existent objects.

Specified by:
createObject in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
Returns:
the new object ID

markForUpdate

public void markForUpdate(long tid,
                          long oid)
Notifies the server that an object is going to be modified.

Specified by:
markForUpdate in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
oid - the object ID

getObject

public byte[] getObject(long tid,
                        long oid,
                        boolean forUpdate)
Obtains the data associated with an object ID. If the forUpdate parameter is true, the caller is stating its intention to modify the object.

Specified by:
getObject in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
oid - the object ID
forUpdate - whether the caller intends to modify the object
Returns:
the data associated with the object ID

setObject

public void setObject(long tid,
                      long oid,
                      byte[] data)
Specifies data to associate with an object ID.

Specified by:
setObject in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
oid - the object ID
data - the data

setObjects

public void setObjects(long tid,
                       long[] oids,
                       byte[][] dataArray)
Specifies data to associate with a series of object IDs.

Specified by:
setObjects in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
oids - the object IDs
dataArray - the associated data values

removeObject

public void removeObject(long tid,
                         long oid)
Removes the object with the specified object ID.

Specified by:
removeObject in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
oid - the object ID

getBinding

public BindingValue getBinding(long tid,
                               String name)
Obtains the object ID bound to a name. If the name is bound, the return value contains the object ID that the name is bound to and a next name of null. If the name is not bound, the return value contains an object ID of -1 and the next name found, which may be null.

Specified by:
getBinding in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
name - the name
Returns:
information about the object ID and the next name

setBinding

public BindingValue setBinding(long tid,
                               String name,
                               long oid)
Binds an object ID to a name. If the name is bound, the return value contains an arbitrary non-negative object ID and a next name of null. If the name is not bound, the return value contains an object ID of -1 and the next name found, which may be null.

Specified by:
setBinding in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
name - the name
oid - the object ID
Returns:
information about the object ID and the next name

removeBinding

public BindingValue removeBinding(long tid,
                                  String name)
Removes the binding for a name. If the name is bound, the return value contains an arbitrary non-negative object ID, otherwise it contains -1. In all cases, the return value contains the next name found, which may be null.

Specified by:
removeBinding in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
name - the name
Returns:
information about the object ID and the next name

nextBoundName

public String nextBoundName(long tid,
                            String name)
Returns the next name after the specified name that has a binding, or null if there are no more bound names. If name is null, then the search starts at the beginning.

Specified by:
nextBoundName in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
name - the name to search after, or null to start at the beginning
Returns:
the next name with a binding following name, or null if there are no more bound names

getClassId

public int getClassId(long tid,
                      byte[] classInfo)
Returns the class ID to represent classes with the specified class information. Obtains an existing ID for the class information if present; otherwise, stores the information and returns the new ID associated with it. Class IDs are always greater than 0. The class information is the serialized form of the ObjectStreamClass instance that serialization uses to represent the class.

Specified by:
getClassId in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
classInfo - the class information
Returns:
the associated class ID

getClassInfo

public byte[] getClassInfo(long tid,
                           int classId)
                    throws ClassInfoNotFoundException
Returns the class information associated with the specified class ID. The class information is the serialized form of the ObjectStreamClass instance that serialization uses to represent the class.

Specified by:
getClassInfo in interface DataStoreServer
Parameters:
tid - the ID of the transaction under which the operation should take place
classId - the class ID
Returns:
the associated class information
Throws:
ClassInfoNotFoundException - if the ID is not found

nextObjectId

public long nextObjectId(long tid,
                         long oid)
Returns the object ID for the next object after the object with the specified ID, or -1 if there are no more objects. If objectId is -1, then returns the ID of the first object. The IDs returned by this method will not include ones for objects that have already been removed, and may not include identifiers for objects created after an iteration has begun. It is not an error for the object associated with the specified identifier to have already been removed.

Specified by:
nextObjectId in interface DataStoreServer
Parameters:
tid - the ID of the transaction
oid - the identifier of the object to search after, or -1 to request the first object
Returns:
the identifier of the next object following the object with identifier oid, or -1 if there are no more objects

createTransaction

public long createTransaction(long timeout)
Creates a new transaction, and returns the associated ID, which will not be negative.

Specified by:
createTransaction in interface DataStoreServer
Parameters:
timeout - the number of milliseconds the resulting transaction should be allowed to run before it times out
Returns:
the ID of the new transaction

prepare

public boolean prepare(long tid)
Prepares the transaction to commit. Returns true when no state was modified, and neither commit or abort should be called.

Specified by:
prepare in interface DataStoreServer
Parameters:
tid - the ID of the transaction
Returns:
true if this participant is read-only, otherwise false

commit

public void commit(long tid)
Commits the transaction.

Specified by:
commit in interface DataStoreServer
Parameters:
tid - the ID of the transaction

prepareAndCommit

public void prepareAndCommit(long tid)
Prepares and commits the transaction.

Specified by:
prepareAndCommit in interface DataStoreServer
Parameters:
tid - the ID of the transaction

abort

public void abort(long tid)
Aborts the transaction.

Specified by:
abort in interface DataStoreServer
Parameters:
tid - the ID of the transaction

shutdown

public void shutdown()
Shuts down this server. Calls to this method will block until the shutdown is complete.


getPort

public int getPort()
Returns the port being used for the server.

Returns:
the port

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a string representation of this object

reapExpiredTransactions

void reapExpiredTransactions()
Find transactions that are expired and not in use, and tell the data store to abort them. The data store needs this nudging to notice that it can perform the abort.


RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved