本文整理汇总了Java中org.jgroups.util.Util.objectFromByteBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java Util.objectFromByteBuffer方法的具体用法?Java Util.objectFromByteBuffer怎么用?Java Util.objectFromByteBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.util.Util
的用法示例。
在下文中一共展示了Util.objectFromByteBuffer方法的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: sendResponses
import org.jgroups.util.Util; //导入方法依赖的package包/类
protected void sendResponses() {
if(responses != null) {
Object obj;
for(int i=0; i < responses.length; i++) {
if(delay > 0)
Util.sleep(delay);
obj=responses[i];
if(obj == null) {
System.err.println("object was null");
continue;
}
if(obj instanceof Message) {
Message msg=(Message)obj;
Address sender=msg.getSrc();
Object retval=null;
try {
retval=Util.objectFromByteBuffer(msg.getBuffer());
}
catch(Exception e) {
e.printStackTrace();
}
request.receiveResponse(retval, sender, false);
}
else if(obj instanceof View)
request.viewChange((View)obj);
}
}
}
示例3: dejgroup
import org.jgroups.util.Util; //导入方法依赖的package包/类
/**
* JGroup 反序列化
*
* byte[] -> object
*
* @param value
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T dejgroup(byte[] value) {
T result = null;
//
AssertHelper.notNull(value, "The Value must not be null");
//
try {
result = (T) Util.objectFromByteBuffer(value);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
}
return result;
}
示例4: dejgroup
import org.jgroups.util.Util; //导入方法依赖的package包/类
/**
* JGroup 反序列化
*
* byte[] -> object
*
* @param value
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T dejgroup(byte[] value) {
T result = null;
//
AssertHelper.notNull(value, "The Value must not be null");
//
try {
result = (T) Util.objectFromByteBuffer(value);
} catch (Exception e) {
LOGGER.error(new StringBuilder("Exception encountered during dejgroup()").toString(), e);
} finally {
}
return result;
}
示例5: receiveMessage
import org.jgroups.util.Util; //导入方法依赖的package包/类
/**
* Handles a message coming from a layer below
*
* @return true if the message was consumed, don't pass it further up, else false
*/
public boolean receiveMessage(Message msg) {
Header hdr=(Header)msg.getHeader(this.id);
if(hdr == null)
return false;
// Check if the message was sent by a request correlator with the same name;
// there may be multiple request correlators in the same protocol stack
if(hdr.corrId != this.id) {
if(log.isTraceEnabled())
log.trace(new StringBuilder("id of request correlator header (").append(hdr.corrId).
append(") is different from ours (").append(this.id).append("). Msg not accepted, passed up"));
return false;
}
if(hdr instanceof MultiDestinationHeader) {
// if we are part of the exclusion list, then we discard the request (addressed to different members)
Address[] exclusion_list=((MultiDestinationHeader)hdr).exclusion_list;
if(exclusion_list != null && local_addr != null && Util.contains(local_addr, exclusion_list)) {
if(log.isTraceEnabled())
log.trace("%s: discarded request from %s as we are in the exclusion list, hdr=",
local_addr, msg.getSrc(), hdr);
return true; // don't pass this message further up
}
}
// [Header.REQ]:
// i. If there is no request handler, discard
// ii. Check whether priority: if synchronous and call stack contains
// address that equals local address -> add priority request. Else
// add normal request.
//
// [Header.RSP]:
// Remove the msg request correlator header and notify the associated
// <tt>RspCollector</tt> that a reply has been received
switch(hdr.type) {
case Header.REQ:
handleRequest(msg, hdr);
break;
case Header.RSP:
case Header.EXC_RSP:
RspCollector coll=requests.get(hdr.id);
if(coll != null) {
boolean is_exception=hdr.type == Header.EXC_RSP;
Address sender=msg.getSrc();
Object retval;
byte[] buf=msg.getRawBuffer();
int offset=msg.getOffset(), length=msg.getLength();
try {
retval=marshaller != null? marshaller.objectFromBuffer(buf, offset, length) :
Util.objectFromByteBuffer(buf, offset, length);
}
catch(Exception e) {
log.error("failed unmarshalling buffer into return value", e);
retval=e;
is_exception=true;
}
coll.receiveResponse(retval, sender, is_exception);
}
break;
default:
msg.getHeader(this.id);
if(log.isErrorEnabled()) log.error("header's type is neither REQ nor RSP !");
break;
}
return true; // message was consumed
}
示例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);
}