import edu.vt.cs.collab.cork.ObjectID; import edu.vt.cs.collab.cork.ReplicatedObjectClient; import edu.vt.cs.collab.cork.impl.inet.InetClient; import edu.vt.cs.collab.cork.search.RetrievableCriteria; /** * Simple CORK client that retrieves or creates a replicated TestBean. * Should be executed with server host and port number as arguments. */ public class Client2 { /** * Our replicated object client */ private ReplicatedObjectClient client = null; /** * Replicated TestBean instance */ private TestBean testBean = null; public Client2(String host, int port) { try { client = new InetClient(host, port, InetClient.SOCKET); client.login("my-id", "my-password"); // Connection and login succeeded if we got to this point. See // if a TestBean has already been created. RetrievableCriteria crit = new RetrievableCriteria(client.getUser(), TestBean.class); ObjectID ids[] = client.getIdentifiers(crit); if ((ids == null) || (ids.length == 0)) { // The search didn't find TestBeans, so we create one testBean = (TestBean) client.getNewObject(TestBean.class, null); } else { // We have at least one TestBean replica in the server. We // could do other tests if we had more than one, but for // this demo we just take the first one. testBean = (TestBean) client.getObject(ids[0]); } } catch(SecurityException se) { System.err.println("Login failed: "); se.printStackTrace(); } catch(Exception e) { System.err.println("Client connection error: "); e.printStackTrace(); } } public static void main(String[] args) { int port = Integer.parseInt(args[1]); Client2 c = new Client2(args[0], port); } }