ConvertServiceImplpublic class ConvertServiceImpl extends UnicastRemoteObject implements ServiceIDListener, ConvertServiceProxy
Fields Summary |
---|
private ServerLandlord | lord | private ServerDelivery | sender | private ConvertServiceLogHandler | handler | private ReliableLog | log | private long | seqNo | private ServiceID | id |
Constructors Summary |
---|
public ConvertServiceImpl(String logDir)
handler = new ConvertServiceLogHandler();
try {
ConvertServiceUpdateRecord csur = new ConvertServiceUpdateRecord();
log = new ReliableLog(logDir, handler);
log.recover();
log.snapshot(); // Clean out all past updates
} catch (Exception e) {
throw new RemoteException("Can't create log", e);
}
lord = new ServerLandlord();
sender = new ServerDelivery(this, lord);
|
Methods Summary |
---|
public java.lang.String | convert(Lease l, int i)
Hashtable cache = (Hashtable) lord.getSessionData(l);
if (cache == null)
throw new LeaseDeniedException("Lease expired");
Integer I = new Integer(i);
String s;
s = (String) cache.get(I);
if (s == null) {
s = I.toString();
cache.put(I, s);
}
sender.deliver(i, getNextSeq());
return s;
| public ConvertServiceRegistration | getInstance(long duration)
Hashtable ht = new Hashtable(13);
return new ConvertServiceRegistrationImpl(this, lord.newLease(ht, duration));
| private synchronized long | getNextSeq()
seqNo++;
try {
// Update the log with the new seq no; we must wrap
// this into an object for the update method
ConvertServiceUpdateRecord csur = new ConvertServiceUpdateRecord();
csur.seqNo = this.seqNo;
log.update(csur, true);
} catch (Exception e) {
e.printStackTrace();
}
return seqNo;
| public static void | main(java.lang.String[] args)
System.setSecurityManager(new RMISecurityManager());
String[] groups = new String[] { "" };
// Create the instance of the service; the JoinManager will
// register it and renew its leases with the lookup service
ConvertServiceImpl csi = (ConvertServiceImpl) new ConvertServiceImpl("csiLog");
JoinManager manager = null;
if (csi.id != null)
manager = new JoinManager(csi.id, csi, null, groups, null, null);
else manager = new JoinManager(csi, null, groups, null, csi, null);
| public void | serviceIDNotify(ServiceID id)
this.id = id;
try {
log.snapshot();
} catch (Exception e) {
e.printStackTrace();
}
| public synchronized EventRegistration | trackConversions(long duration, RemoteEventListener rel, java.rmi.MarshalledObject key)
return sender.addListener(rel, duration, key, seqNo);
|
|