本文整理汇总了Java中org.jgroups.Message.writeTo方法的典型用法代码示例。如果您正苦于以下问题:Java Message.writeTo方法的具体用法?Java Message.writeTo怎么用?Java Message.writeTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.Message
的用法示例。
在下文中一共展示了Message.writeTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMcastDiscoveryRequest
import org.jgroups.Message; //导入方法依赖的package包/类
@Override
protected void sendMcastDiscoveryRequest(Message msg) {
try {
if(msg.getSrc() == null)
msg.setSrc(local_addr);
ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(128);
msg.writeTo(out);
for(int i=bind_port; i <= bind_port+port_range; i++) {
DatagramPacket packet=new DatagramPacket(out.buffer(), 0, out.position(), dest_addr, i);
sock.send(packet);
}
}
catch(Exception ex) {
log.error("failed sending discovery request", ex);
}
}
示例2: testResponse
import org.jgroups.Message; //导入方法依赖的package包/类
@Test
public void testResponse() throws Exception {
Address local_addr = pinger.getLocalAddress();
PhysicalAddress physical_addr = (PhysicalAddress) pinger
.down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
PingData data = createPingData(local_addr, physical_addr);
final PingHeader hdr = getPingHeader(data);
Message msg = new Message(null).setFlag(Message.Flag.DONT_BUNDLE)
.putHeader(pinger.getId(), hdr).setBuffer(streamableToBuffer(data));
URL url = new URL("http://localhost:8888");
HttpURLConnection conn = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
conn.addRequestProperty(Server.CLUSTER_NAME, TestBase.CLUSTER_NAME);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
msg.writeTo(out);
out.flush();
Assert.assertEquals(200, conn.getResponseCode());
}
示例3: fragment
import org.jgroups.Message; //导入方法依赖的package包/类
/**
* Send all fragments as separate messages (with same ID !).
* Example:
* <pre>
* Given the generated ID is 2344, number of fragments=3, message {dst,src,buf}
* would be fragmented into:
* <p/>
* [2344,3,0]{dst,src,buf1},
* [2344,3,1]{dst,src,buf2} and
* [2344,3,2]{dst,src,buf3}
* </pre>
*/
private void fragment(Message msg, long size) {
Address dest=msg.getDest(), src=msg.getSrc();
long frag_id=curr_id.getAndIncrement(); // used as seqnos
int num_frags;
try {
// write message into a byte buffer and fragment it
ByteArrayDataOutputStream dos=new ByteArrayDataOutputStream((int)(size + 50));
msg.writeTo(dos);
byte[] buffer=dos.buffer();
byte[][] fragments=Util.fragmentBuffer(buffer, frag_size, dos.position());
num_frags=fragments.length;
num_sent_frags+=num_frags;
if(log.isTraceEnabled()) {
StringBuilder sb=new StringBuilder();
sb.append("fragmenting packet to ").append(dest != null ? dest.toString() : "<all members>");
sb.append(" (size=").append(buffer.length).append(") into ").append(num_frags);
sb.append(" fragment(s) [frag_size=").append(frag_size).append(']');
log.trace(sb.toString());
}
for(int i=0; i < num_frags; i++) {
Message frag_msg=new Message(dest, src, fragments[i]);
FragHeader hdr=new FragHeader(frag_id, i, num_frags);
frag_msg.putHeader(this.id, hdr);
Event evt=new Event(Event.MSG, frag_msg);
down_prot.down(evt);
}
}
catch(Exception e) {
log.error("exception occurred trying to fragment message", e);
}
}
示例4: sendMcastDiscoveryRequest
import org.jgroups.Message; //导入方法依赖的package包/类
@Override
protected void sendMcastDiscoveryRequest(Message msg) {
try {
if(msg.getSrc() == null)
msg.setSrc(local_addr);
ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(128);
msg.writeTo(out);
Buffer buf=out.getBuffer();
DatagramPacket packet=new DatagramPacket(buf.getBuf(), buf.getOffset(), buf.getLength(), mcast_addr, mcast_port);
if(mcast_send_sockets != null) {
MulticastSocket s;
for(int i=0; i < mcast_send_sockets.length; i++) {
s=mcast_send_sockets[i];
try {
s.send(packet);
}
catch(Exception e) {
log.error("failed sending packet on socket " + s);
}
}
}
else { // DEFAULT path
if(mcast_sock != null)
mcast_sock.send(packet);
}
}
catch(Exception ex) {
log.error("failed sending discovery request", ex);
}
}
示例5: writeMessage
import org.jgroups.Message; //导入方法依赖的package包/类
protected static final void writeMessage(final Message msg, DataOutputStream out) throws Exception {
byte flags=0;
if(msg.getDest() == null)
flags+=(byte)2;
out.writeShort(Version.version); // write the version
out.writeByte(flags);
msg.writeTo(out);
}
示例6: writeMessage
import org.jgroups.Message; //导入方法依赖的package包/类
protected Buffer writeMessage(final Message msg) throws Exception {
dos.position(0);
byte flags=0;
dos.writeShort(Version.version); // write the version
if(msg.getDest() == null)
flags+=(byte)2;
dos.writeByte(flags);
msg.writeTo(dos);
return new Buffer(dos.buffer(), 0, dos.position());
}
示例7: writeMessage
import org.jgroups.Message; //导入方法依赖的package包/类
protected static void writeMessage(Message msg, DataOutput dos, boolean multicast) throws Exception {
byte flags=0;
dos.writeShort(Version.version); // write the version
if(multicast)
flags+=MULTICAST;
dos.writeByte(flags);
msg.writeTo(dos);
}