当前位置: 首页>>代码示例>>Java>>正文


Java ClusterSerializable类代码示例

本文整理汇总了Java中io.vertx.core.shareddata.impl.ClusterSerializable的典型用法代码示例。如果您正苦于以下问题:Java ClusterSerializable类的具体用法?Java ClusterSerializable怎么用?Java ClusterSerializable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClusterSerializable类属于io.vertx.core.shareddata.impl包,在下文中一共展示了ClusterSerializable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extendeSessionShouldBeClusterSerializable

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Test
public void extendeSessionShouldBeClusterSerializable() throws InterruptedException {
    SessionImpl delegate = new SessionImpl(3000);
    ExtendedSession extendedSession = ExtendedSession.adapt(delegate);
    assertThat(extendedSession).isInstanceOf(ClusterSerializable.class);
    long createdAt = extendedSession.createdAt();
    extendedSession.put("key1", "value");
    extendedSession.put("key2", 20);
    Thread.sleep(300);

    Buffer buffer = Buffer.buffer();
    ((ClusterSerializable) extendedSession).writeToBuffer(buffer);
    assertThat(buffer.length() > 0);

    ExtendedSession fromBuffer = ExtendedSession.adapt(new SessionImpl(0));
    ((ClusterSerializable) fromBuffer).readFromBuffer(0, buffer);
    assertThat(fromBuffer.createdAt()).isEqualTo(createdAt);
    assertThat(fromBuffer.id()).isEqualTo(delegate.id());
    assertThat(fromBuffer.timeout()).isEqualTo(delegate.timeout());
    assertThat(fromBuffer.data()).isEqualTo(delegate.data());

}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:23,代码来源:ExtendedSessionUT.java

示例2: asByte

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
protected byte[] asByte(Object object) throws IOException {
  ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  DataOutput dataOutput = new DataOutputStream(byteOut);
  if (object instanceof ClusterSerializable) {
    ClusterSerializable clusterSerializable = (ClusterSerializable) object;
    dataOutput.writeBoolean(true);
    dataOutput.writeUTF(object.getClass().getName());
    Buffer buffer = Buffer.buffer();
    clusterSerializable.writeToBuffer(buffer);
    byte[] bytes = buffer.getBytes();
    dataOutput.writeInt(bytes.length);
    dataOutput.write(bytes);
  } else {
    dataOutput.writeBoolean(false);
    ByteArrayOutputStream javaByteOut = new ByteArrayOutputStream();
    ObjectOutput objectOutput = new ObjectOutputStream(javaByteOut);
    objectOutput.writeObject(object);
    dataOutput.write(javaByteOut.toByteArray());
  }
  return byteOut.toByteArray();
}
 
开发者ID:IBYoung,项目名称:vert.3x-gateway,代码行数:22,代码来源:ZKMap.java

示例3: readExternal

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  boolean isClusterSerializable = in.readBoolean();
  if (isClusterSerializable) {
    String className = in.readUTF();
    Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
    try {
      data = (T) clazz.newInstance();
      byte[] bytes = new byte[in.read()];
      in.read(bytes);
      ((ClusterSerializable) data).readFromBuffer(0, Buffer.buffer(bytes));
    } catch (InstantiationException | IllegalAccessException e) {
      throw new VertxException(e);
    }
  } else {
    data = (T) in.readObject();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-jgroups,代码行数:19,代码来源:DataHolder.java

示例4: writeToBuffer

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Override
public void writeToBuffer(Buffer buffer) {
  // try to get the user from the context otherwise fall back to any cached version
  User user = context != null ? context.user() : this.user;
  if (user != null && user instanceof ClusterSerializable) {
    buffer.appendByte((byte)1);
    String className = user.getClass().getCanonicalName();
    if (className == null) {
      throw new IllegalStateException("Cannot serialize " + user.getClass().getName());
    }
    byte[] bytes = className.getBytes(StandardCharsets.UTF_8);
    buffer.appendInt(bytes.length);
    buffer.appendBytes(bytes);
    ClusterSerializable cs = (ClusterSerializable)user;
    cs.writeToBuffer(buffer);
  } else {
    buffer.appendByte((byte)0);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:20,代码来源:UserHolder.java

示例5: readFromBuffer

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Override
public int readFromBuffer(int pos, Buffer buffer) {
  byte b = buffer.getByte(pos++);
  if (b == (byte)1) {
    int len = buffer.getInt(pos);
    pos += 4;
    byte[] bytes = buffer.getBytes(pos, pos + len);
    pos += len;
    String className = new String(bytes, StandardCharsets.UTF_8);
    try {
      Class clazz = Utils.getClassLoader().loadClass(className);
      ClusterSerializable obj = (ClusterSerializable) clazz.newInstance();
      pos = obj.readFromBuffer(pos, buffer);
      user = (User) obj;
    } catch (Exception e) {
      throw new VertxException(e);
    }
  } else {
    user = null;
  }
  return pos;
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:23,代码来源:UserHolder.java

示例6: unmarshal0

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
private static ClusterSerializable unmarshal0(ClusterSerializableValue value) {
  try {
    Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(value.getClassName());
    ClusterSerializable obj = (ClusterSerializable) cls.newInstance();
    obj.readFromBuffer(0, Buffer.buffer(value.getData()));
    return obj;
  } catch (Exception e) {
    throw new IllegalStateException("Failed to load class " + value.getClassName(), e);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-ignite,代码行数:11,代码来源:ClusterSerializationUtils.java

示例7: toCachedObject

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
public static <T> Object toCachedObject(T t) {
  if (t instanceof ServerID) {
    return new InfinispanServerID((ServerID) t);
  }
  if (t instanceof ClusterNodeInfo) {
    return new InfinispanClusterNodeInfo((ClusterNodeInfo) t);
  }
  if (t instanceof ClusterSerializable) {
    return new InfinispanClusterSerializable((ClusterSerializable) t);
  }
  return t;
}
 
开发者ID:vert-x3,项目名称:vertx-infinispan,代码行数:13,代码来源:DataConverter.java

示例8: createSerializer

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
/**
 * Creates a new Vert.x compatible serializer.
 */
private Serializer createSerializer() {
  return Serializer.using(KryoNamespace.builder()
      .setRegistrationRequired(false)
      .register(KryoNamespaces.BASIC)
      .register(ServerID.class)
      .register(new ClusterSerializableSerializer<>(), ClusterSerializable.class)
      .build());
}
 
开发者ID:atomix,项目名称:atomix-vertx,代码行数:12,代码来源:AtomixClusterManager.java

示例9: writeExternal

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Override
public void writeExternal(ObjectOutput out) throws IOException {
  boolean isClusterSerializable = ClusterSerializable.class.isInstance(data);
  out.writeBoolean(isClusterSerializable);
  if (isClusterSerializable) {
    out.writeUTF(data.getClass().getName());
    Buffer buffer = Buffer.buffer();
    ((ClusterSerializable) data).writeToBuffer(buffer);
    byte[] bytes = buffer.getBytes();
    out.write(bytes.length);
    out.write(bytes);
  } else {
    out.writeObject(data);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-jgroups,代码行数:16,代码来源:DataHolder.java

示例10: put

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Override
public void put(Session session, Handler<AsyncResult<Void>> resultHandler) {
  ClusterSerializable cs = (ClusterSerializable)session;
  Buffer buff = Buffer.buffer();
  cs.writeToBuffer(buff);
  sessions.put(session.id(), buff);
  vertx.runOnContext(v -> resultHandler.handle(Future.succeededFuture()));
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:9,代码来源:BasicAuthHandlerTest.java

示例11: convertParam

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T convertParam(T obj) {
  if (obj instanceof ClusterSerializable) {
    ClusterSerializable cobj = (ClusterSerializable) obj;
    return (T) (new DataSerializableHolder(cobj));
  } else {
    return obj;
  }
}
 
开发者ID:vert-x3,项目名称:vertx-hazelcast,代码行数:10,代码来源:ConversionUtils.java

示例12: readData

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Override
public void readData(ObjectDataInput objectDataInput) throws IOException {
  String className = objectDataInput.readUTF();
  int length = objectDataInput.readInt();
  byte[] bytes = new byte[length];
  objectDataInput.readFully(bytes);
  try {
    Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
    clusterSerializable = (ClusterSerializable) clazz.newInstance();
    clusterSerializable.readFromBuffer(0, Buffer.buffer(bytes));
  } catch (Exception e) {
    throw new IllegalStateException("Failed to load class " + e.getMessage(), e);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-hazelcast,代码行数:15,代码来源:ConversionUtils.java

示例13: writeToBuffer

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Override
public void writeToBuffer(Buffer buffer) {
    buffer.appendLong(createdAt);
    ((ClusterSerializable) delegate).writeToBuffer(buffer);
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:6,代码来源:ExtendedSessionImpl.java

示例14: readFromBuffer

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
@Override
public int readFromBuffer(int pos, Buffer buffer) {
    createdAt = buffer.getLong(pos);
    return ((ClusterSerializable) delegate).readFromBuffer(pos + 8, buffer);
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:6,代码来源:ExtendedSessionImpl.java

示例15: marshal0

import io.vertx.core.shareddata.impl.ClusterSerializable; //导入依赖的package包/类
private static ClusterSerializableValue marshal0(ClusterSerializable obj) {
  Buffer buffer = Buffer.buffer();
  obj.writeToBuffer(buffer);
  return new ClusterSerializableValue(obj.getClass().getName(), buffer.getBytes());
}
 
开发者ID:vert-x3,项目名称:vertx-ignite,代码行数:6,代码来源:ClusterSerializationUtils.java


注:本文中的io.vertx.core.shareddata.impl.ClusterSerializable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。