tp.impl
Class CSEP545ServiceObject

java.lang.Object
  extended by tp.impl.CSEP545ServiceObject
All Implemented Interfaces:
Remote, CSEP545Service
Direct Known Subclasses:
MyRM, MyTM, MyWC

public abstract class CSEP545ServiceObject
extends Object
implements CSEP545Service

A stub class to drive project services.

Bootstrap

The bootstrap happens in the following order.
  1. process common command line arguments
  2. cleanup storage directory if necessary
  3. init(String[])
  4. initStorage() if initializing the storage or recovery() if storage exists
  5. startUp()
  6. Registry.rebind(String, Remote)
  7. readyToServe()

Common arguments

The following arguments are processed by this class.
ArgumentDescriptionDefault
-n name or --name name the name of service Type of service
-p port or --port port port number to bind the service anonymous port
-d dir or --dir dir the data directory where all necessary files are. './' ServiceID '-data'
--init initialize the data directory. will wipe out data directory if it exists. initialize if data directory does not exist, recovery() otherwise. Do not force initialization
--rmiHost host host name of RMI registry 127.0.0.1
--rmiPort port port number of RMI registry. 1099
-c URI or --code URI RMI server code base URL http://127.0.0.1:8080/csep545.jar


Nested Class Summary
 
Nested classes/interfaces inherited from interface tp.impl.CSEP545Service
CSEP545Service.Type
 
Field Summary
protected  File dir
          directory to store all data files
protected  Registry registry
          reference to RMI registry
protected  ServiceID svcid
          service identifier.
 
Constructor Summary
CSEP545ServiceObject()
           
 
Method Summary
 File getDataRoot()
          Get root directory where local data files are located.
 ServiceID getServiceID()
          Name of remote service object
protected abstract  void init(String[] args)
          IMPLEMENT THIS METHOD process command line parameters and setup any parameterized values.
protected abstract  void initStorage()
          IMPLEMENT THIS METHOD Initialize necessary data files.
 void kill()
          Immediately kill remote service.
protected
<T extends Remote>
Map<String,T>
lookupRemote(CSEP545Service.Type type)
           
protected
<T extends Remote>
T
lookupRemote(CSEP545Service.Type type, String name)
          utility method to resolve remote object
protected
<T extends Remote>
T
lookupRemote(ServiceID id)
          utility method to resolve remote object
protected
<T extends Remote>
T
lookupRemote(String name)
          utility method to resolve remote object
static void main(String[] args)
           
protected abstract  void readyToServe()
          IMPLEMENT THIS METHOD Bootstrapping completed and the server is up and running.
protected abstract  void recovery()
          IMPLEMENT THIS METHOD Run recovery algorithm and reconstruct the state of service before failure.
 void shutdown()
          Gracefully shutdown target service.
protected abstract  void startUp()
          IMPLEMENT THIS METHOD If you use extra threads in your service, start them in this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface tp.impl.CSEP545Service
refresh
 

Field Detail

svcid

protected ServiceID svcid
service identifier. must be unique per instance.


dir

protected File dir
directory to store all data files


registry

protected transient Registry registry
reference to RMI registry

Constructor Detail

CSEP545ServiceObject

public CSEP545ServiceObject()
Method Detail

kill

public final void kill()
                throws RemoteException
Description copied from interface: CSEP545Service
Immediately kill remote service. Useful for automated testing.

Specified by:
kill in interface CSEP545Service
Throws:
RemoteException

shutdown

public void shutdown()
              throws RemoteException
Description copied from interface: CSEP545Service
Gracefully shutdown target service. On restart, the service should not need to recover its state. Please make sure to call Registry.unbind(String)

Specified by:
shutdown in interface CSEP545Service
Throws:
RemoteException
See Also:
Registry.unbind(String)

getServiceID

public final ServiceID getServiceID()
Description copied from interface: CSEP545Service
Name of remote service object

Specified by:
getServiceID in interface CSEP545Service
Returns:
A string represent remote service object

getDataRoot

public final File getDataRoot()
Get root directory where local data files are located. By default, getServiceID() '-data' under working directory.

Returns:
root directory to place data files

init

protected abstract void init(String[] args)
                      throws Exception
IMPLEMENT THIS METHOD process command line parameters and setup any parameterized values. For example, setting self destruct counter should be done in this method.

Parameters:
args - command line arguments except common arguments
Throws:
Exception

initStorage

protected abstract void initStorage()
                             throws Exception
IMPLEMENT THIS METHOD Initialize necessary data files. Invoked in two cases. For example, you can create database files for RM and commit log file for TM

Throws:
Exception

recovery

protected abstract void recovery()
                          throws Exception
IMPLEMENT THIS METHOD Run recovery algorithm and reconstruct the state of service before failure. This method is invoked when the data directory already exists. Note that if the service has been shutdown cleanly, calling this method should not affect the state.

Throws:
Exception

startUp

protected abstract void startUp()
                         throws Exception
IMPLEMENT THIS METHOD If you use extra threads in your service, start them in this method. For example, you can launch periodic deadlock-detector thread here. Or, any kinds of asynchronous taks such as timeout-retry, failure detector, etc.

Throws:
Exception

readyToServe

protected abstract void readyToServe()
                              throws Exception
IMPLEMENT THIS METHOD Bootstrapping completed and the server is up and running.

Throws:
Exception

lookupRemote

protected <T extends Remote> T lookupRemote(String name)
                                 throws AccessException,
                                        RemoteException,
                                        NotBoundException
utility method to resolve remote object

Parameters:
name - bind name of remote object
Returns:
remote object stub
Throws:
AccessException
RemoteException
NotBoundException

lookupRemote

protected <T extends Remote> T lookupRemote(ServiceID id)
                                 throws AccessException,
                                        RemoteException,
                                        NotBoundException
utility method to resolve remote object

Parameters:
id - bind name of remote object
Returns:
remote object stub
Throws:
AccessException
RemoteException
NotBoundException

lookupRemote

protected <T extends Remote> T lookupRemote(CSEP545Service.Type type,
                                            String name)
                                 throws AccessException,
                                        RemoteException,
                                        NotBoundException
utility method to resolve remote object

Parameters:
type - type of remove object
Returns:
remote object stub
Throws:
AccessException
RemoteException
NotBoundException

lookupRemote

protected <T extends Remote> Map<String,T> lookupRemote(CSEP545Service.Type type)
                                             throws AccessException,
                                                    RemoteException,
                                                    NotBoundException
Throws:
AccessException
RemoteException
NotBoundException

main

public static void main(String[] args)
                 throws Exception
Parameters:
args -
Throws:
Exception