Refine search
/** * Helper method to create a Message with given parameters and invoke {@link #send(Message)}. * @param dst destination address for the message. If null, the message will be sent to all cluster members * @param obj a serializable object. Will be marshalled into the byte buffer of the message. If it * is <em>not</em> serializable, an exception will be thrown * @throws Exception exception thrown if message sending was not successful */ public JChannel send(Address dst, Object obj) throws Exception { return send(new Message(dst, obj)); }
/** * Sends a message. See {@link #send(Address,byte[],int,int)} for details * @param dst destination address for the message. If null, the message will be sent to all cluster members * @param buf buffer message payload * @throws Exception exception thrown if the message sending was not successful */ public JChannel send(Address dst, byte[] buf) throws Exception { return send(new Message(dst, buf)); }
/** * Sends a message to a destination. * * @param dst the destination address. If null, the message will be sent to all cluster nodes (= cluster members) * @param buf the buffer to be sent * @param offset the offset into the buffer * @param length the length of the data to be sent. Has to be <= buf.length - offset. This will send * {@code length} bytes starting at {@code offset} * @throws Exception thrown if send() failed */ public JChannel send(Address dst, byte[] buf, int offset, int length) throws Exception { return send(new Message(dst, buf, offset, length)); }
private void eventLoop() { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); while(true) { try { System.out.print("> "); System.out.flush(); String line=in.readLine().toLowerCase(); if(line.startsWith("quit") || line.startsWith("exit")) { break; } Message msg=new Message(null, line); channel.send(msg); } catch(Exception ignored) { } } }
public void mouseDragged(MouseEvent e) { int x=e.getX(), y=e.getY(); graphics.fillOval(x, y, 10, 10); try { out.reset(); outstream=new DataOutputStream(out); outstream.writeInt(red); outstream.writeInt(green); outstream.writeInt(blue); outstream.writeInt(x); outstream.writeInt(y); channel.send(new Message(null, out.toByteArray())); out.reset(); } catch(Exception ex) { log.error(ex.toString()); } }
public void mouseDragged(MouseEvent e) { int x=e.getX(), y=e.getY(); DrawCommand comm=new DrawCommand(DrawCommand.DRAW, x, y, draw_color.getRGB()); if(no_channel) { drawPoint(comm); return; } try { byte[] buf=Util.streamableToByteBuffer(comm); if(use_unicasts) sendToAll(buf); else channel.send(new Message(null, buf)); } catch(Exception ex) { System.err.println(ex); } }
protected void sendOwnState(final Map<Point,Color> copy) { if(copy == null) return; for(Point point: copy.keySet()) { // we don't need the color: it is our draw_color anyway DrawCommand comm=new DrawCommand(DrawCommand.DRAW, point.x, point.y, draw_color.getRGB()); try { byte[] buf=Util.streamableToByteBuffer(comm); if(use_unicasts) sendToAll(buf); else channel.send(new Message(null, buf)); } catch(Exception ex) { System.err.println(ex); } } }
public void receive(Message msg) { Address sender=msg.getSrc(); System.out.println("<< " + msg.getObject() + " from " + sender); Address dst=msg.getDest(); if(dst == null) { Message rsp=new Message(msg.getSrc(), "this is a response"); try { ch.send(rsp); } catch(Exception e) { e.printStackTrace(); } } }
public void run() { for(int i=1; i <= number_of_msgs; i++) { try { Message msg=new Message(destination, buf); if(oob) msg.setFlag(Message.Flag.OOB); if(dont_bundle) msg.setFlag(Message.Flag.DONT_BUNDLE); if(i > 0 && print > 0 && i % print == 0) System.out.println("-- sent " + i); channel.send(msg); if(sleep_time > 0) Util.sleep(sleep_time); } catch(Exception e) { e.printStackTrace(); } } } }
void sendMessages() throws Exception { Address destination=getReceiver(); if(destination == null) { System.err.println("UnicastTest.sendMessages(): receiver is null, cannot send messages"); return; } if(num_threads > 1 && num_msgs % num_threads != 0) { System.err.println("num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")"); return; } System.out.println("sending " + num_msgs + " messages (" + Util.printBytes(msg_size) + ") to " + destination + ": oob=" + oob + ", " + num_threads + " sender thread(s)"); ByteBuffer buf=ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs); Message msg=new Message(destination, buf.array()); channel.send(msg); long print=num_msgs / 10; int msgs_per_sender=num_msgs / num_threads; Sender[] senders=new Sender[num_threads]; for(int i=0; i < senders.length; i++) senders[i]=new Sender(msgs_per_sender, msg_size, destination, (int)print); for(Sender sender: senders) sender.start(); for(Sender sender: senders) sender.join(); System.out.println("done sending " + num_msgs + " to " + destination); }
/** Forwards the message across the TCP link to the other local cluster */ protected void forward(byte[] buffer, int offset, int length) { Message msg=new Message(null, buffer, offset, length).putHeader(id, new RelayHeader(RelayHeader.Type.FORWARD)); if(bridge != null) { try { bridge.send(msg); } catch(Throwable t) { log.error(Util.getMessage("FailedForwardingMessageOverBridge"), t); } } }
public void receive(Message msg) { byte type=msg.getRawBuffer()[msg.getOffset()]; switch(type) { case PING: final Message rsp=new Message(msg.getSrc(), PONG_RSP); rsp.setFlag(Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC); try { ch.send(rsp); } catch(Exception e) { e.printStackTrace(); } break; case PONG: long rtt=System.nanoTime() - start; double ms=rtt / 1000.0 / 1000.0; System.out.printf("RTT for %s: %.2f ms\n", msg.src(), ms); break; } }
private void sendMessages() throws Exception { System.out.println("Start sending messages..."); String address = jChannel.getAddressAsString(); List<Address> mbrs = jChannel.getView().getMembers(); start = System.nanoTime(); for (int i = 0; i < numberOfMessages; ++i) { AnycastAddress dst = getDestinations(mbrs); Message message = new Message().dest(dst); DataMessage dataMessage = new DataMessage(); dataMessage.type = DataMessage.DATA; dataMessage.data = address + ":" + i; message.setObject(dataMessage); jChannel.send(message); sentBytes += (dataMessage.data.getBytes().length + 1); sentMessages++; } stop = System.nanoTime(); System.out.println("Finish sending messages..."); }