Hello!!!
I will first tell u the mechanism then it will b ez for u to understand.......
Here,4 classes related to RMICallbackSever,RMICallbackServerImpl,RMICallbackClient & RMICallbackClientImpl work in the same manner as RMI Calls work.....but the problem which i m facing is that I ve sequences in one file then i m reading that sequences from a file n break into 3 equal files named as client1,...,client3, by using SequenceReader class ...
But i ve to implement distribute method by server so that it will distribute the different files to different registered clients...n then registered client used algorithm by using dosimMatch n then in the last result will be collected........
So plz help me in this regard..How i can implement distribute method by sending different files to different registered clients........
Take care..
Here are the all five classes till yet..
import java.rmi.*;
// It's an interface used by server
public interface RMICallbackServer extends Remote{
public static final
String registry_name="CallbackServer";
public abstract void register(RMICallbackClient client) throws RemoteException; // This is the method for registration of clients..
public abstract void deregister(RMICallbackClient client) throws RemoteException; // This is the method for deregistration of clients...
public abstract void say(String message) throws RemoteException;
//public abstract void distribute(String st1,String st2) throws RemoteException; // This is the method for distribution for different files to registered clients....
// This is the implementation class of RMICallbackServer
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.io.*;
public class RMICallbackServerImpl extends UnicastRemoteObject implements RMICallbackServer{
public RMICallbackServerImpl() throws RemoteException
{
tables= new Hashtable();
count=0;
str1="ACKETKDISAAXZIML";
str2="ADKKLAKLKLIWEOEWL";
}
public void register(RMICallbackClient client)
{
try{
count=count+1;
key= String.valueOf(count);
tables.put(key,getClientHost());
say(getClientHost() + " has Joined");
}
catch(ServerNotActiveException ignored){
}
clients.addElement(client);
System.out.println("Total Clients:" + count);
System.out.println(tables.toString());
clients=tables.keys();
while(clients.hasMoreElements())
{
st=(String) clients.nextElement();
System.out.println(st + " " + tables.get(st));
}
}
public void deregister(RMICallbackClient client) {
try{
say(getClientHost() + " has left.");
count=count-1;
System.out.println("Total Clients:" + count);
tables.remove(key);
}
catch(ServerNotActiveException ignored){}
}
public void say(String message)
{
System.out.println(message);
}
public void distribute(String str1,String str2)
{
//System.out.println("HASHTABLE:"+tables);
//SequenceReader sr=new SequenceReader();
//sr.loadBalance();
}
public static void main(String[] args) throws RemoteException
{
RMICallbackServerImpl callbackServer=new RMICallbackServerImpl();
Registry registry=LocateRegistry.getRegistry();
registry.rebind(registry_name,callbackServer);
}
protected static Hashtable tables;
protected static int count;
protected static Object key;
protected static String result;
protected static String str1,str2,st;
protected long time,times;
}
}
// This is the interface for Client....
import java.rmi.*;
public interface RMICallbackClient extends Remote{
public abstract String doSimMatch(String s1,String s2) throws RemoteException;
}
// This is the class for Client........
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class RMICallbackClientImpl extends UnicastRemoteObject
implements RMICallbackClient
{
protected String host;
protected double result;
protected int[][] sim;
protected int gap = -1;
protected int match = 1;
protected int mismatch = -1;
protected int len1, len2;
protected String s1, s2,output;
protected RMICallbackServer server;
public RMICallbackClientImpl(String Host) throws RemoteException
{
this.host=host;
}
public synchronized void start() throws RemoteException,NotBoundException
{
if(server== null){
Registry registry=LocateRegistry.getRegistry(host);
server=(RMICallbackServer) registry.lookup (RMICallbackServer.registry_name);
server.register(this);
sleep(500);
server.distribute(server.str1,server.str2);
}
}
public synchronized void stop() throws RemoteException
{
RMICallbackServer server=this.server;
this.server=null;
if(server !=null)
server.deregister(this);
}
public String doSimMatch(String s1,String s2)
{
len1 = s1.length();
len2 = s2.length();
this.s1 = s1;
this.s2 = s2;
sim = new int[len1+1][len2+1];
int i,j;
for ( i=0; i<=len1; i++)
sim[i][0] = i*gap;
for ( j=0; j<=len2; j++)
sim[0][j] = j*gap;
for (i = 1; i<=len1; i++)
for (j = 1; j<=len2; j++)
if (s1.charAt(i-1) == s2.charAt(j-1))
sim[i][j] = maximum(sim[i-1][j]+gap,sim[i-1][j-1]+match,
sim[i][j-1]+gap);
else
sim[i][j] = maximum(sim[i-1][j]+gap,sim[i-1][j-1]+mismatch,
sim[i][j-1]+gap);
return(" "+sim[len1][len2]);
}
static int maximum(int i, int j, int k)
{
return Math.max(i,Math.max(j,k));
}
public static void main(String[] args) throws RemoteException,NotBoundException
{
if(args.length != 1)
throw new IllegalArgumentException
("Syntax:RMICallbackClientImpl <host>");
RMICallbackClientImpl callbackClient=new RMICallbackClientImpl("127.0.0.1");
callbackClient.start();
}
}
// This is the class for Reading Sequence..........
import java.util.StringTokenizer;
import java.io.*;
import java.util.*;
public class SequenceReader
{
public void loadBalance()
{
//String str1="DKDAIELS";
try
{
BufferedReader in = new BufferedReader(new FileReader("se.txt"));
BufferedWriter bw;
String currLine= new String();
String name;
String fileNameRoot = "CLIENT";
SequenceReader sr=new SequenceReader();
while ( (currLine = in.readLine()) != null )
{
StringTokenizer tokens=new StringTokenizer(currLine);
num=tokens.countTokens();
//System.out.println(num);
count=num/3;
//System.out.println("String For Matching "+ str1);
for(int i=0;i<3;i++)
{
name = fileNameRoot + (i+1) + ".TXT";
bw = new BufferedWriter(new FileWriter(name));
System.out.println("Client" + (i+1));
while (tokens.hasMoreTokens() && count!=0) {
//System.out.println(tokens.nextToken());
String tn=tokens.nextToken();
bw.write(tn);
bw.write(" ");
count=count-1;
}
bw.close();
count=num/3;
//System.out.println(num);
}
}
in.close();
}
catch (IOException e) { System.err.println(e); }
}
}