1 31 package org.objectweb.proactive.examples.cs; 32 33 import org.apache.log4j.Logger; 34 import org.objectweb.proactive.core.config.ProActiveConfiguration; 35 36 52 public class Server { 53 54 static Logger logger = Logger.getLogger(Server.class.getName()); 55 56 protected String messageOfTheDay; 57 protected java.util.ArrayList clients; 58 59 60 public Server() { 61 } 62 63 64 public Server(String messageOfTheDay) { 65 this.clients = new java.util.ArrayList (); 66 this.messageOfTheDay = messageOfTheDay; 67 } 68 69 70 public String getMessageOfTheDay() { 71 return messageOfTheDay; 72 } 73 74 75 public void setMessageOfTheDay(String messageOfTheDay) { 76 logger.info("Server: new message: " + messageOfTheDay); 77 this.messageOfTheDay = messageOfTheDay; 78 this.notifyClients(); 79 } 80 81 82 public void register(Client c) { 83 this.clients.add(c); 84 } 85 86 87 public void unregister(Client c) { 88 this.clients.remove(c); 89 } 90 91 92 protected void notifyClients() { 93 java.util.Iterator it = this.clients.iterator(); 94 Client currentClient; 95 96 while (it.hasNext()) { 97 currentClient = (Client)it.next(); 98 try { 99 currentClient.messageChanged(this.messageOfTheDay); 100 } catch (Exception t) { 101 it.remove(); 102 } 103 } 104 } 105 106 107 public static void main(String [] args) { 108 ProActiveConfiguration.load(); 109 try { 110 Server theServer = (Server)org.objectweb.proactive.ProActive.newActive(Server.class.getName(), new Object []{"This is the first message"}); 112 114 org.objectweb.proactive.ProActive.register(theServer, "///theServer"); 116 117 System.out.println("Server is ready."); 118 } catch (Exception e) { 119 e.printStackTrace(); 120 } 121 } 122 } | Popular Tags |