Java Collaborative Computing
              Java collaborative computing across computers.
 
 
  Getting Start  
 
The main entrance to the services is EndPoint. EndPoint is single instance. To make it work, you don't need to config anything.

 
  Get The EndPoint Instance  
  Very simple. You don't need to do any configuration work.
		EndPoint instance = EndPoint.getInstance();
 
  Message Service  
  The message service is provided by class MessageService. You can get the instance from EndPoint:
			MessageService service = instance.getMessageService();
		
 
  Receive  
  To receive Message, you need create a MessageReceiver:
import net.jcc.message.Message;
import net.jcc.message.MessageReceiver;

public class ConsoleMessageReceiver implements MessageReceiver {

	public static final int CONSOLE_SLOT = 0;

	// The concept of 'slot' here is similar with message type. Only message
	// with this slot will be received by this receiver.
	public int getSlot() {
		return CONSOLE_SLOT;
	}

	public void receive(Message msg) {
		System.out.println(msg.getData().toString());//just print it
	}

}
		
Then, register this message receiver:
			service.registerReceiver(new ConsoleMessageReceiver());
		
The message receiver is ready to receive message.
 
  Send  
  Call the sendMessage method of message service.
			service.sendMessage(new StringMessage(ConsoleMessageReceiver.CONSOLE_SLOT, "Hello"));//send message to all other hosts
		
Note that send message code should be executed on another hosts.
 
  Remote Procedure Call Service  
  The remote procedure call service is provided by class RemoteProcedureRegistry. You can get the instance from EndPoint:
			RemoteProcedureRegistry registry = instance.getRemoteProcedureRegistry();
		
 
  Prepare Procedure  
  Create a procedure:

import java.io.Serializable;
import java.util.List;

import net.jcc.rpc.RemoteException;
import net.jcc.rpc.RemoteProcedure;

public class PrintProcedure implements RemoteProcedure {

	public Serializable call(List args) throws RemoteException {
		for(Object o : args){
			System.out.println(o);
		}
		return args.size() + " args printed";
	}

	public String getName() {
		return "print";
	}

}
		
Then, register this procedure:
			registry.register(new PrintProcedure());
		
The procedure is ready to be called.
 
  Call a remote procedure  
  To send a message, you need to get the MessageService instance, then call the send method.
			ArrayList params = new ArrayList();
			params.add("args1");
			params.add("args2");
			Object result = registry.call("hostname", "print", params);
			System.out.println("Call result is:" + result);
		
Note that call code should be executed on another hosts.
 
  Shared Object Service  
  The shared object service is provided by class SharedObjectPool. You can get the instance from EndPoint:
			SharedObjectPool pool = instance.getSharedObjectPool();
		
 
  Add a shared object  
 
			SharedObject obj = pool.add("asdf");
			System.out.println("New shared object created, id is:" + obj.getId());
		
 
  Update a shared object  
 
			obj.set("fdsa");
		
 
  Get object in shared object  
 
			Object o = obj.get();
		
 
  Get shared object in another host  
 
			int id = 0;//The id of the shared object, you need to know it first.
			SharedObject obj = pool.get("hostname", id);
		
You can operate this shared object same with the shared object stored in local. While the value of the shared object is updated, it will send update notification to all shared object instance in other hosts.
 
  ...And That's All You Need To Start!