diff options
author | slewis | 2007-03-19 23:56:47 +0000 |
---|---|---|
committer | slewis | 2007-03-19 23:56:47 +0000 |
commit | 8c515d9571f7e8dac7814d0774d534a456602b87 (patch) | |
tree | b8219749b1c8a4032d1e8200feb684438c9d55cc /examples/bundles/org.eclipse.ecf.example.clients | |
parent | 270bc3dbeba2b96cdad0d10f612191e85b638582 (diff) | |
download | org.eclipse.ecf-8c515d9571f7e8dac7814d0774d534a456602b87.tar.gz org.eclipse.ecf-8c515d9571f7e8dac7814d0774d534a456602b87.tar.xz org.eclipse.ecf-8c515d9571f7e8dac7814d0774d534a456602b87.zip |
Cleaned up code in example clients
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.example.clients')
3 files changed, 51 insertions, 35 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatRobotApplication.java b/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatRobotApplication.java index 3f0cd1a7f..569b901e4 100644 --- a/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatRobotApplication.java +++ b/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatRobotApplication.java @@ -59,12 +59,15 @@ public class ChatRobotApplication implements IPlatformRunnable, client.setupPresence(); // Then connect - client.doConnect(userName + "@" + hostName, password); + String connectTarget = userName + "@" + hostName; + client.doConnect(connectTarget, password); + + System.out.println("ECF chat robot ("+connectTarget+")"); // Send initial message to target user client .sendChat(targetIMUser, - "Hi, I'm an IM robot. You probably don't want to talk with me."); + "Hi, I'm an ECF chat robot."); running = true; int count = 0; diff --git a/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatRoomRobotApplication.java b/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatRoomRobotApplication.java index bcd99343e..b458fda96 100644 --- a/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatRoomRobotApplication.java +++ b/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatRoomRobotApplication.java @@ -27,8 +27,8 @@ import org.eclipse.ecf.presence.im.IChatMessage; * and make sure you have all required plug-ins. * */ -public class ChatRoomRobotApplication implements IPlatformRunnable, IMessageReceiver, - IIMMessageListener { +public class ChatRoomRobotApplication implements IPlatformRunnable, + IMessageReceiver, IIMMessageListener { private IChatRoomMessageSender sender; @@ -40,14 +40,14 @@ public class ChatRoomRobotApplication implements IPlatformRunnable, IMessageRece if (args instanceof Object[]) { Object[] arguments = (Object[]) args; int l = arguments.length; - if (arguments[l-1] instanceof String - && arguments[l-2] instanceof String - && arguments[l-3] instanceof String - && arguments[l-4] instanceof String) { - userName = (String) arguments[l-4]; - String hostName = (String) arguments[l-3]; - String password = (String) arguments[l-2]; - String roomName = (String) arguments[l-1]; + if (arguments[l - 1] instanceof String + && arguments[l - 2] instanceof String + && arguments[l - 3] instanceof String + && arguments[l - 4] instanceof String) { + userName = (String) arguments[l - 4]; + String hostName = (String) arguments[l - 3]; + String password = (String) arguments[l - 2]; + String roomName = (String) arguments[l - 1]; runRobot(hostName, password, roomName); return new Integer(0); } @@ -60,12 +60,19 @@ public class ChatRoomRobotApplication implements IPlatformRunnable, IMessageRece private void runRobot(String hostName, String password, String roomName) throws ECFException, Exception, InterruptedException { XMPPChatRoomClient client = new XMPPChatRoomClient(this); - client.connect(userName + "@" + hostName, password); + + // Then connect + String connectTarget = userName + "@" + hostName; + + client.connect(connectTarget, password); IChatRoomContainer room = client.createChatRoom(roomName); room.connect(client.getChatRoomInfo().getRoomID(), null); - System.out.println(room.getConnectedID().getName()); + System.out.println("ECF chat room robot (" + connectTarget + + "). Connected to room: " + + client.getChatRoomInfo().getRoomID().getName()); + room.addMessageListener(this); sender = room.getChatRoomMessageSender(); running = true; @@ -87,7 +94,7 @@ public class ChatRoomRobotApplication implements IPlatformRunnable, IMessageRece notifyAll(); } - public void handleMessage(ID fromID, String messageBody) { + public void handleChatRoomMessage(ID fromID, String messageBody) { // message in chat room if (fromID.getName().startsWith(userName + "@")) { // my own message, don't respond @@ -115,7 +122,7 @@ public class ChatRoomRobotApplication implements IPlatformRunnable, IMessageRece if (messageEvent instanceof IChatRoomMessageEvent) { IChatRoomMessage m = ((IChatRoomMessageEvent) messageEvent) .getChatRoomMessage(); - handleMessage(m.getFromID(), m.getMessage()); + handleChatRoomMessage(m.getFromID(), m.getMessage()); } } diff --git a/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatSORobotApplication.java b/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatSORobotApplication.java index d52082b82..c9f9c4730 100644 --- a/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatSORobotApplication.java +++ b/examples/bundles/org.eclipse.ecf.example.clients/src/org/eclipse/ecf/example/clients/applications/ChatSORobotApplication.java @@ -24,7 +24,7 @@ public class ChatSORobotApplication implements IPlatformRunnable, public static final int WAIT_TIME = 10000; public static final int WAIT_COUNT = 10; - + private boolean running = false; private String userName; private XMPPChatClient client; @@ -34,14 +34,14 @@ public class ChatSORobotApplication implements IPlatformRunnable, if (args instanceof Object[]) { Object[] arguments = (Object[]) args; int l = arguments.length; - if (arguments[l-1] instanceof String - && arguments[l-2] instanceof String - && arguments[l-3] instanceof String - && arguments[l-4] instanceof String) { - userName = (String) arguments[l-4]; - String hostName = (String) arguments[l-3]; - String password = (String) arguments[l-2]; - String targetName = (String) arguments[l-1]; + if (arguments[l - 1] instanceof String + && arguments[l - 2] instanceof String + && arguments[l - 3] instanceof String + && arguments[l - 4] instanceof String) { + userName = (String) arguments[l - 4]; + String hostName = (String) arguments[l - 3]; + String password = (String) arguments[l - 2]; + String targetName = (String) arguments[l - 1]; runRobot(hostName, password, targetName); return new Integer(0); } @@ -64,7 +64,11 @@ public class ChatSORobotApplication implements IPlatformRunnable, createSharedObject(); // Then connect - client.doConnect(userName + "@" + hostName, password); + String connectTarget = userName + "@" + hostName; + + client.doConnect(connectTarget, password); + + System.out.println("ECF chat robot connected to: " + connectTarget); // Send initial message to target user client.sendChat(targetIMUser, "Hi, I'm an IM robot"); @@ -75,24 +79,26 @@ public class ChatSORobotApplication implements IPlatformRunnable, // out-of-band via shared object while (running && count++ < WAIT_COUNT) { // Send shared object message - sharedObject.sendMessageTo(client.createID(targetIMUser), count + " hello there"); + sharedObject.sendMessageTo(client.createID(targetIMUser), count + + " hello there"); wait(WAIT_TIME); } } protected void createSharedObject() throws ECFException { ISharedObjectContainer socontainer = (ISharedObjectContainer) client - .getContainer().getAdapter(ISharedObjectContainer.class); - // Create TrivialSharedObject - sharedObject = new TrivialSharedObject(); - // Add shared object to container - socontainer.getSharedObjectManager().addSharedObject(IDFactory.getDefault().createStringID( - TrivialSharedObject.class.getName()), - sharedObject, null); + .getContainer().getAdapter(ISharedObjectContainer.class); + // Create TrivialSharedObject + sharedObject = new TrivialSharedObject(); + // Add shared object to container + socontainer.getSharedObjectManager().addSharedObject( + IDFactory.getDefault().createStringID( + TrivialSharedObject.class.getName()), sharedObject, + null); } public synchronized void handleMessage(IChatMessage chatMessage) { - System.out.println("handleMessage("+chatMessage+")"); + System.out.println("handleMessage(" + chatMessage + ")"); } } |