Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
hellogroup [2013/09/25 13:54] mroriz [Execution] |
hellogroup [2017/07/21 03:08] (current) |
||
---|---|---|---|
Line 453: | Line 453: | ||
===== HelloGroupDefinerClient ===== | ===== HelloGroupDefinerClient ===== | ||
+ | Our client will act slightly the same as the '' | ||
+ | <file java HelloGroupClient.java> | ||
+ | package br.pucrio.inf.lac.helloworld; | ||
+ | |||
+ | import java.io.IOException; | ||
+ | import java.net.InetSocketAddress; | ||
+ | import java.net.SocketAddress; | ||
+ | import java.util.List; | ||
+ | import java.util.logging.Level; | ||
+ | import java.util.logging.Logger; | ||
+ | |||
+ | import lac.cnclib.net.NodeConnection; | ||
+ | import lac.cnclib.net.NodeConnectionListener; | ||
+ | import lac.cnclib.net.groups.Group; | ||
+ | import lac.cnclib.net.groups.GroupCommunicationManager; | ||
+ | import lac.cnclib.net.groups.GroupMembershipListener; | ||
+ | import lac.cnclib.net.mrudp.MrUdpNodeConnection; | ||
+ | import lac.cnclib.sddl.message.ApplicationMessage; | ||
+ | import lac.cnclib.sddl.message.Message; | ||
+ | |||
+ | public class HelloGroupClient implements NodeConnectionListener, | ||
+ | |||
+ | private final static String | ||
+ | private final static int | ||
+ | private GroupCommunicationManager | ||
+ | |||
+ | public HelloGroupClient() { | ||
+ | InetSocketAddress address = new InetSocketAddress(gatewayIP, | ||
+ | try { | ||
+ | MrUdpNodeConnection connection = new MrUdpNodeConnection(); | ||
+ | connection.connect(address); | ||
+ | connection.addNodeConnectionListener(this); | ||
+ | |||
+ | try { | ||
+ | Thread.sleep(30000); | ||
+ | } catch (InterruptedException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } catch (IOException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public static void main(String[] args) { | ||
+ | Logger.getLogger("" | ||
+ | |||
+ | new HelloGroupClient(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void connected(NodeConnection remoteCon) { | ||
+ | groupManager = new GroupCommunicationManager(remoteCon); | ||
+ | groupManager.addMembershipListener(this); | ||
+ | |||
+ | try { | ||
+ | // i = 1 Default | ||
+ | // i = 2 EVEN | ||
+ | // i = 3 ODD | ||
+ | for (int i = 1; i < 4; i++) { | ||
+ | Group group = new Group(3, i); | ||
+ | |||
+ | ApplicationMessage appMsg = new ApplicationMessage(); | ||
+ | appMsg.setContentObject(" | ||
+ | groupManager.sendGroupcastMessage(appMsg, | ||
+ | } | ||
+ | } catch (IOException e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void reconnected(NodeConnection remoteCon, SocketAddress endPoint, boolean wasHandover, | ||
+ | |||
+ | @Override | ||
+ | public void disconnected(NodeConnection remoteCon) {} | ||
+ | |||
+ | @Override | ||
+ | public void newMessageReceived(NodeConnection remoteCon, Message message) { | ||
+ | System.out.println(message.getContentObject()); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void unsentMessages(NodeConnection remoteCon, List< | ||
+ | |||
+ | @Override | ||
+ | public void internalException(NodeConnection remoteCon, Exception e) {} | ||
+ | |||
+ | @Override | ||
+ | public void enteringGroups(List< | ||
+ | |||
+ | @Override | ||
+ | public void leavingGroups(List< | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== HelloGroupDefinerExecution ===== | ||
+ | The execution of our application is identical to the others example, if there is no gateway executing we need to create one to instantiate the core infrastructure. To do that, open a shell, and run the following command: | ||
+ | |||
+ | $ gateway 127.0.0.1 5500 | ||
+ | |||
+ | After that, we instantiate the GroupDefiner, |