本文整理汇总了Java中org.jgroups.util.Util.objectToByteBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java Util.objectToByteBuffer方法的具体用法?Java Util.objectToByteBuffer怎么用?Java Util.objectToByteBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.util.Util
的用法示例。
在下文中一共展示了Util.objectToByteBuffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void run() {
while (running) {
buf = new byte[16000];
mcast_packet = new DatagramPacket(buf, buf.length);
try {
mcast_sock.receive(mcast_packet);
req = (DiscoveryRequest) Util.objectFromByteBuffer(mcast_packet.getData());
System.out.println("<-- " + req);
// send response back to req.sender_addr
rsp = new DiscoveryResponse(new InetSocketAddress(local_addr, local_port), req.sender_addr.getAddress());
buf = Util.objectToByteBuffer(rsp);
rsp_packet = new DatagramPacket(buf, buf.length, req.sender_addr);
sock.send(rsp_packet);
} catch (Exception ex) {
System.err.println("McastReceiver.run(): " + ex + ", rsp_packet=" +
rsp_packet.getSocketAddress() + ", length=" + rsp_packet.getLength() + " bytes");
ex.printStackTrace();
}
}
}
示例2: sendDiscoveryRequest
import org.jgroups.util.Util; //导入方法依赖的package包/类
void sendDiscoveryRequest() {
DiscoveryRequest req;
byte[] buf;
DatagramPacket packet;
req = new DiscoveryRequest(local_addr, local_port);
System.out.println("--> " + req);
try {
buf = Util.objectToByteBuffer(req);
packet = new DatagramPacket(buf, buf.length, mcast_addr, mcast_port);
mcast_sock.send(packet);
} catch (Exception ex) {
System.err.println("McastDiscovery.sendDiscoveryRequest(): " + ex);
}
}
示例3: sendReply
import org.jgroups.util.Util; //导入方法依赖的package包/类
protected void sendReply(final Message req, final long req_id, Object reply, boolean is_exception) {
Object rsp_buf; // either byte[] or Buffer
try { // retval could be an exception, or a real value
rsp_buf=marshaller != null? marshaller.objectToBuffer(reply) : Util.objectToByteBuffer(reply);
}
catch(Throwable t) {
try { // this call should succeed (all exceptions are serializable)
rsp_buf=marshaller != null? marshaller.objectToBuffer(t) : Util.objectToByteBuffer(t);
is_exception=true;
}
catch(NotSerializableException not_serializable) {
if(log.isErrorEnabled()) log.error("failed marshalling rsp (" + reply + "): not serializable");
return;
}
catch(Throwable tt) {
if(log.isErrorEnabled()) log.error("failed marshalling rsp (" + reply + "): " + tt);
return;
}
}
Message rsp=req.makeReply().setFlag(req.getFlags()).clearFlag(Message.Flag.RSVP, Message.Flag.SCOPED);
if(rsp_buf instanceof Buffer)
rsp.setBuffer((Buffer)rsp_buf);
else if(rsp_buf instanceof byte[])
rsp.setBuffer((byte[])rsp_buf);
sendResponse(rsp, req_id, is_exception);
}
示例4: jgroup
import org.jgroups.util.Util; //导入方法依赖的package包/类
/**
* JGroup 序列化
*
* object -> byte[]
*
* @param value
* @return
*/
public static byte[] jgroup(Serializable value) {
byte[] result = new byte[0];
//
AssertHelper.notNull(value, "The Value must not be null");
//
try {
result = Util.objectToByteBuffer(value);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
}
return result;
}
示例5: jgroup
import org.jgroups.util.Util; //导入方法依赖的package包/类
/**
* JGroup 序列化
*
* object -> byte[]
*
* @param value
* @return
*/
public static byte[] jgroup(Object value) {
AssertHelper.notNull(value, "The Value must not be null");
//
byte[] result = new byte[0];
try {
result = Util.objectToByteBuffer(value);
} catch (Exception e) {
LOGGER.error(new StringBuilder("Exception encountered during jgroup()").toString(), e);
} finally {
}
return result;
}
示例6: marshalAndUnmarshal
import org.jgroups.util.Util; //导入方法依赖的package包/类
private static MethodCall marshalAndUnmarshal(MethodCall m) throws Exception {
byte[] buf=Util.objectToByteBuffer(m);
System.out.println("marshalled buffer size: " + buf.length + " bytes");
return (MethodCall)Util.objectFromByteBuffer(buf);
}