public void sendToAll(Message msg) { lock (this) { try { byte[] data = msg.Serialize(); socket.Send(data); //Logger.getInstance().log("Sending: [" + msg.ToString() + "]", LOGGING_NAME, Logger.Level.INFO); } catch (SocketException ex) { Logger.getInstance().log("SocketException: " + ex.Message, LOGGING_NAME, Logger.Level.WARNING); } } }
public void sendToNode(Message message, IPEndPoint to) { lock (this) { // begin-user-code byte[] data; if (to == null) { // write to self try { queue.put(message); } catch (ThreadInterruptedException) { Logger.getInstance().log("InterruptedException Cannot send to self", LOGGING_NAME, Logger.Level.SEVERE); } return; } // serialize data = message.Serialize(); NodeInfo node = null; if (nodes.ContainsKey(to)) { node = nodes[to]; } if (node == null) { Logger.getInstance().log("Request to send to unexisting node: " + to.ToString(), LOGGING_NAME, Logger.Level.WARNING); } else { if (!writeToNode(to, node.getSocket(), data)) { nodes.Remove(to); } } // end-user-code } }
public void sendToAllServerNodes(Message message) { lock (this) { // begin-user-code byte[] data; // serialize data = message.Serialize(); // search for server nodes IDictionaryEnumerator it = nodes.GetEnumerator(); //Iterator<Map.Entry<InetSocketAddress, NodeInfo>> it = nodes.entrySet().iterator(); // w javie while (it.MoveNext()) { NodeInfo node = (NodeInfo)it.Value; if (node.getIsServer()) { if (!writeToNode((IPEndPoint)it.Key, node.getSocket(), data)) { // TODO nie czaję tego kawałka -- usuwamy nodes.Remove((IPEndPoint)it.Key); //it.remove(); // w javie } } } // write to self try { queue.put(message); } catch (ThreadInterruptedException) { Logger.getInstance().log("InterruptedException Cannot send to self", LOGGING_NAME, Logger.Level.SEVERE); } } // end-user-code }