本文整理了Java中org.jgroups.util.Util.objectToByteBuffer()
方法的一些代码示例,展示了Util.objectToByteBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.objectToByteBuffer()
方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:objectToByteBuffer
[英]Serializes/Streams an object into a byte buffer. The object has to implement interface Serializable or Externalizable or Streamable.
[中]将对象序列化/流式传输到字节缓冲区。对象必须实现可序列化、可外部化或可流化的接口。
代码示例来源:origin: wildfly/wildfly
public ConfigChange(String attr_name, Object val) throws Exception {
this.attr_name=attr_name;
this.attr_value=Util.objectToByteBuffer(val);
}
代码示例来源:origin: wildfly/wildfly
public ConfigChange(String attr_name, Object val) throws Exception {
this.attr_name=attr_name;
this.attr_value=Util.objectToByteBuffer(val);
}
代码示例来源:origin: wildfly/wildfly
public static void writeObject(Object obj,DataOutput out) throws Exception {
if(obj instanceof Streamable) {
out.writeInt(-1);
writeGenericStreamable((Streamable)obj,out);
}
else {
byte[] buf=objectToByteBuffer(obj);
out.writeInt(buf.length);
out.write(buf,0,buf.length);
}
}
代码示例来源:origin: wildfly/wildfly
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);
}
}
代码示例来源:origin: wildfly/wildfly
public void writeTo(DataOutput out) throws Exception {
out.writeByte(type.ordinal());
// We can't use Util.writeObject since it's size is limited to 2^15-1
try {
if (object instanceof Streamable) {
out.writeShort(-1);
Util.writeGenericStreamable((Streamable)object, out);
}
else {
byte[] bytes = Util.objectToByteBuffer(object);
out.writeInt(bytes.length);
out.write(bytes);
}
}
catch (IOException e) {
throw e;
}
catch (Exception e) {
throw new IOException("Exception encountered while serializing execution request", e);
}
out.writeLong(request);
}
代码示例来源:origin: wildfly/wildfly
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();
}
}
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Takes an object and uses Java serialization to generate the byte[] buffer which is set in the
* message. Parameter 'obj' has to be serializable (e.g. implementing Serializable,
* Externalizable or Streamable, or be a basic type (e.g. Integer, Short etc)).
*/
public Message setObject(Object obj) {
if(obj == null) return this;
if(obj instanceof byte[])
return setBuffer((byte[])obj);
if(obj instanceof Buffer)
return setBuffer((Buffer)obj);
try {
return setBuffer(Util.objectToByteBuffer(obj));
}
catch(Exception ex) {
throw new IllegalArgumentException(ex);
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
public byte[] getState() {
try {
return Util.objectToByteBuffer(history);
}
catch(Exception e) {
return null;
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
public static long sizeOf(Object inst) {
byte[] data;
try {
data=Util.objectToByteBuffer(inst);
return data.length;
}
catch(Exception ex) {
return -1;
}
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
public ConfigChange(String attr_name, Object val) throws Exception {
this.attr_name=attr_name;
this.attr_value=Util.objectToByteBuffer(val);
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
public byte[] getState() { // return the copy previously saved by saveState()
try {
return Util.objectToByteBuffer(copy);
}
catch(Throwable ex) {
ex.printStackTrace();
return null;
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
public byte[] getState() {
byte[] retval=null;
if(state == null) return null;
synchronized(state) {
try {
retval=Util.objectToByteBuffer(state);
}
catch(Exception e) {
e.printStackTrace();
}
}
return retval;
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
public byte[] getState() {
try {
return Util.objectToByteBuffer(stocks.clone());
}
catch(Exception ex) {
ex.printStackTrace();
return null;
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
/** Return a copy of the current cache (tree) */
public byte[] getState() {
try {
return Util.objectToByteBuffer(root.clone());
}
catch(Throwable ex) {
if(log.isErrorEnabled()) log.error("exception returning cache: " + ex);
return null;
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
public byte[] getState()
{
Vector copy = (Vector)getContents().clone();
try
{
return Util.objectToByteBuffer(copy);
}
catch (Throwable ex)
{
logger.error("DistributedQueue.getState(): exception marshalling state.", ex);
return null;
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
/** Return a copy of the tree */
public byte[] getState() {
Object copy=root != null? root.copy() : null;
try {
return Util.objectToByteBuffer(copy);
}
catch(Throwable ex) {
if(log.isErrorEnabled()) log.error("exception marshalling state: " + ex);
return null;
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
public static void writeObject(Object obj, DataOutputStream out) throws Exception {
if(obj == null || !(obj instanceof Streamable)) {
byte[] buf=objectToByteBuffer(obj);
out.writeShort(buf.length);
out.write(buf, 0, buf.length);
}
else {
out.writeShort(-1);
writeGenericStreamable((Streamable)obj, out);
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
public static long sizeOf(String classname) {
Object inst;
byte[] data;
try {
inst=Util.loadClass(classname, null).newInstance();
data=Util.objectToByteBuffer(inst);
return data.length;
}
catch(Exception ex) {
return -1;
}
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
public static void writeObject(Object obj,DataOutput out) throws Exception {
if(obj instanceof Streamable) {
out.writeInt(-1);
writeGenericStreamable((Streamable)obj,out);
}
else {
byte[] buf=objectToByteBuffer(obj);
out.writeInt(buf.length);
out.write(buf,0,buf.length);
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
private void sendServiceState() throws Exception {
byte[] data=Util.objectToByteBuffer(new HashSet<String>(services.keySet()));
sendServiceMessage(ServiceInfo.LIST_SERVICES_RSP, null, channel.getLocalAddress(), true, data);
}
内容来源于网络,如有侵权,请联系作者删除!