Sequencer Multicast Protocol Using Java
Sequencer Multicast Protocol Using Java
import java.awt.*;
import java.awt.event.*;
import java.io.PrintStream;
import java.util.EventObject;
1
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == stopIt)
{
group.leave();
System.exit(1);
} else
if(e.getSource() == pauseIt)
paused = !paused;
}
String returned;
Group group;
Thread t;
Scrollbar slider;
2
Button stopIt;
Button pauseIt;
TextField text;
int rate;
String myName;
boolean paused;
}
Group.java
package sequencer;
import java.io.*;
import java.net.*;
import java.rmi.Naming;
import java.util.Date;
int period;
3
public GroupException(String s)
{
super(s);
}
}
myAddr = InetAddress.getLocalHost();
sequencer = (Sequencer)Naming.lookup("//" + host + "/TKSequencer");
myName = name + myAddr;
SequencerJoinInfo joinInfo = sequencer.join(myName);
groupAddr = joinInfo.addr;
lastSequenceRecd = joinInfo.sequence;
System.out.println("ip of group: " + groupAddr);
socket = new MulticastSocket(10000);
socket.joinGroup(groupAddr);
this.handler = handler;
t = new Thread(this);
t.start();
heartBeater = new HeartBeater(5);
heartBeater.start();
}
catch(SequencerException ex)
{
System.out.println("Couldn't create group " + ex);
throw new GroupException(String.valueOf(ex));
}
catch(Exception ex)
{
System.out.println("Couldn't create group " + ex);
throw new GroupException("Couldn't join to sequencer");
}
}
4
throw new GroupException("Couldn't send to sequencer");
}
else
throw new GroupException("Group not joined");
}
}
lastSequenceRecd = gotSequence;
handler.handle(count, buf);
}
}
catch(Exception ex)
{
System.out.println("bad in run " + ex);
}
}
Thread t;
Thread heartBeater;
5
Sequencer sequencer;
MulticastSocket socket;
MsgHandler handler;
long lastSequenceRecd;
long lastSequenceSent;
InetAddress groupAddr;
InetAddress myAddr;
String myName;
long lastSendTime;
}
Sequencer.java
package sequencer;
import java.rmi.Remote;
import java.rmi.RemoteException;
SequencerImpl.java
package sequencer;
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
6
public SequencerImpl(String name)
throws RemoteException
{
this.name = name;
try
{
history = new History();
mySenders = new Vector();
socket = new MulticastSocket();
groupAddr = InetAddress.getByName("228.5.6.7");
// groupAddr = InetAddress.getByName("172.16.4.124");
}
catch(Exception ex)
{
System.out.println("Couldn't initialise seq: " + ex);
}
}
public synchronized void send(String sender, long id, long lastRecd, byte msg[])
throws RemoteException
{
try
{
ByteArrayOutputStream bstream = new ByteArrayOutputStream(10240);
DataOutputStream dstream = new DataOutputStream(bstream);
dstream.writeLong(++sequence);
dstream.write(msg, 0, msg.length);
socket.send(new DatagramPacket(bstream.toByteArray(), bstream.size(), groupAddr, 10000));
}
catch(Exception ex)
{
System.out.println("problem sending by sequ " + ex);
}
history.noteReceived(sender, lastRecd);
history.addMsg(sender, sequence, msg);
}
7
System.out.println("Sequencer supplies missing " + sequence);
return found;
} else
{
System.out.println("Sequencer couldn't find missing " + sequence);
throw new SequencerException("Couldn't find missing " + sequence);
}
}
History.java
package sequencer;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Hashtable;
8
public class History extends Hashtable
{
public History()
{
historyCleanedTo = -1L;
senders = new Hashtable();
}
9
Alte clase sunt:
SequencerJoinInfo.java
package sequencer;
import java.io.Serializable;
import java.net.InetAddress;
SequencerImpl_Skel.java
package sequencer;
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
10
{
throw new UnmarshalException("Error unmarshaling arguments", ioexception6);
}
finally
{
remotecall.releaseInputStream();
}
byte abyte0[] = sequencerimpl.getMissing(l1);
try
{
ObjectOutput objectoutput1 = remotecall.getResultStream(true);
objectoutput1.writeObject(abyte0);
return;
}
catch(IOException ioexception2)
{
throw new MarshalException("Error marshaling return", ioexception2);
}
case 1: // '\001'
String s;
long l2;
try
{
ObjectInput objectinput3 = remotecall.getInputStream();
s = (String)objectinput3.readObject();
l2 = objectinput3.readLong();
}
catch(IOException ioexception7)
{
throw new UnmarshalException("Error unmarshaling arguments", ioexception7);
}
finally
{
remotecall.releaseInputStream();
}
sequencerimpl.heartbeat(s, l2);
try
{
remotecall.getResultStream(true);
return;
}
catch(IOException ioexception3)
{
throw new MarshalException("Error marshaling return", ioexception3);
}
case 2: // '\002'
String s1;
try
{
ObjectInput objectinput = remotecall.getInputStream();
s1 = (String)objectinput.readObject();
}
catch(IOException ioexception4)
{
throw new UnmarshalException("Error unmarshaling arguments", ioexception4);
11
}
finally
{
remotecall.releaseInputStream();
}
SequencerJoinInfo sequencerjoininfo = sequencerimpl.join(s1);
try
{
ObjectOutput objectoutput = remotecall.getResultStream(true);
objectoutput.writeObject(sequencerjoininfo);
return;
}
catch(IOException ioexception1)
{
throw new MarshalException("Error marshaling return", ioexception1);
}
case 3: // '\003'
String s2;
try
{
ObjectInput objectinput1 = remotecall.getInputStream();
s2 = (String)objectinput1.readObject();
}
catch(IOException ioexception5)
{
throw new UnmarshalException("Error unmarshaling arguments", ioexception5);
}
finally
{
remotecall.releaseInputStream();
}
sequencerimpl.leave(s2);
try
{
remotecall.getResultStream(true);
return;
}
catch(IOException ioexception)
{
throw new MarshalException("Error marshaling return", ioexception);
}
case 4: // '\004'
String s3;
long l3;
long l4;
byte abyte1[];
try
{
ObjectInput objectinput4 = remotecall.getInputStream();
s3 = (String)objectinput4.readObject();
l3 = objectinput4.readLong();
l4 = objectinput4.readLong();
abyte1 = (byte[])objectinput4.readObject();
}
catch(IOException ioexception9)
12
{
throw new UnmarshalException("Error unmarshaling arguments", ioexception9);
}
finally
{
remotecall.releaseInputStream();
}
sequencerimpl.send(s3, l3, l4, abyte1);
try
{
remotecall.getResultStream(true);
return;
}
catch(IOException ioexception8)
{
throw new MarshalException("Error marshaling return", ioexception8);
}
}
throw new RemoteException("Method number out of range");
}
public SequencerImpl_Skel()
{
}
SequencerImpl_Stub.java
package sequencer;
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
public SequencerImpl_Stub()
{
}
13
public byte[] getMissing(long l)
throws RemoteException, SequencerException
{
int i = 0;
RemoteRef remoteref = super.ref;
RemoteCall remotecall = remoteref.newCall(this, operations, i, 0x46fe5f6f059e0674L);
try
{
ObjectOutput objectoutput = remotecall.getOutputStream();
objectoutput.writeLong(l);
}
catch(IOException ioexception)
{
throw new MarshalException("Error marshaling arguments", ioexception);
}
try
{
remoteref.invoke(remotecall);
}
catch(RemoteException remoteexception)
{
throw remoteexception;
}
catch(SequencerException sequencerexception)
{
throw sequencerexception;
}
catch(Exception exception)
{
throw new UnexpectedException("Unexpected exception", exception);
}
byte abyte0[];
try
{
ObjectInput objectinput = remotecall.getInputStream();
abyte0 = (byte[])objectinput.readObject();
}
catch(IOException ioexception1)
{
throw new UnmarshalException("Error unmarshaling return", ioexception1);
}
catch(ClassNotFoundException classnotfoundexception)
{
throw new UnmarshalException("Return value class not found", classnotfoundexception);
}
catch(Exception exception2)
{
throw new UnexpectedException("Unexpected exception", exception2);
}
finally
{
remoteref.done(remotecall);
}
return abyte0;
}
14
throws RemoteException
{
int i = 1;
RemoteRef remoteref = super.ref;
RemoteCall remotecall = remoteref.newCall(this, operations, i, 0x46fe5f6f059e0674L);
try
{
ObjectOutput objectoutput = remotecall.getOutputStream();
objectoutput.writeObject(s);
objectoutput.writeLong(l);
}
catch(IOException ioexception)
{
throw new MarshalException("Error marshaling arguments", ioexception);
}
try
{
remoteref.invoke(remotecall);
}
catch(RemoteException remoteexception)
{
throw remoteexception;
}
catch(Exception exception)
{
throw new UnexpectedException("Unexpected exception", exception);
}
remoteref.done(remotecall);
}
15
catch(Exception exception)
{
throw new UnexpectedException("Unexpected exception", exception);
}
SequencerJoinInfo sequencerjoininfo;
try
{
ObjectInput objectinput = remotecall.getInputStream();
sequencerjoininfo = (SequencerJoinInfo)objectinput.readObject();
}
catch(IOException ioexception1)
{
throw new UnmarshalException("Error unmarshaling return", ioexception1);
}
catch(ClassNotFoundException classnotfoundexception)
{
throw new UnmarshalException("Return value class not found", classnotfoundexception);
}
catch(Exception exception2)
{
throw new UnexpectedException("Unexpected exception", exception2);
}
finally
{
remoteref.done(remotecall);
}
return sequencerjoininfo;
}
16
}
17