本文整理汇总了Java中io.protostuff.runtime.RuntimeSchema类的典型用法代码示例。如果您正苦于以下问题:Java RuntimeSchema类的具体用法?Java RuntimeSchema怎么用?Java RuntimeSchema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeSchema类属于io.protostuff.runtime包,在下文中一共展示了RuntimeSchema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* 序列化对象
*
* @param obj
* @param <T>
* @return
*/
public static <T> byte[] serialize(T obj) {
if (obj == null) {
throw new RuntimeException("序列化对象(" + obj + ")为空!");
}
RuntimeSchema<T> schema = RuntimeSchema.createFrom((Class<T>) obj.getClass());
LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
byte[] protoStuff = null;
try {
protoStuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
} catch (Exception e) {
throw new RuntimeException("序列化(" + obj.getClass() + ")对象(" + obj + ")发生异常!", e);
} finally {
buffer.clear();
}
return protoStuff;
}
示例2: put
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* Associates the specified value with the specified key in this map.
* If the map previously contained a mapping for the key, the old
* value is replaced.
*
* @param key key with which the specified value is to be associated
* @param value value to be associated with the specified key
* @return the previous value associated with <tt>key</tt>, or
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
*/
public V put(K key, V value){
Object oldValue = null;
if ((key != null) && ((oldValue = super.hashPut((key.toString()+"�Map�"+gvName), value))!=null)){
// ################ Serialization key ########################
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
ObjectWrap objW = new ObjectWrap(key);
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
// ################ Serialization key ########################
super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
}else{
System.out.println("Null key or fault in put<K,V> on cluster!");
}
return (V)oldValue;
}
示例3: putUnlock
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* Associates the specified value with the specified key in this map.
* If the map previously contained a mapping for the key, the old
* value is replaced.
*
* @param key key with which the specified value is to be associated
* @param value value to be associated with the specified key
* @return the previous value associated with <tt>key</tt>, or
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
*/
public V putUnlock(K key, V value){
V oldValue = null;
if (key != null){
if(DEFAULT_JCL.containsGlobalVar(key.toString()+"�Map�"+gvName)){
oldValue = (V) DEFAULT_JCL.getValue(key.toString()+"�Map�"+gvName).getCorrectResult();
DEFAULT_JCL.setValueUnlocking((key.toString()+"�Map�"+gvName), value);
}else if (DEFAULT_JCL.instantiateGlobalVar((key.toString()+"�Map�"+gvName), value)){
// ################ Serialization key ########################
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
ObjectWrap objW = new ObjectWrap(key);
Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
// ################ Serialization key ########################
super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
}
}else{
System.out.println("Can't put<K,V> with null key!");
}
return (oldValue == null ? null : oldValue);
}
示例4: putAll
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* Copies all of the mappings from the specified map to this map.
* These mappings will replace any mappings that this map had for
* any of the keys currently in the specified map.
*
* @param m mappings to be stored in this map
* @throws NullPointerException if the specified map is null
*/
public void putAll(Map<? extends K, ? extends V> m) {
int numKeysToBeAdded = m.size();
if (numKeysToBeAdded == 0)
return;
super.instantiateBin((Object)m.entrySet(), this.gvName);
List<Object> obj = new ArrayList<Object>();
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
for(K key:m.keySet()){
// ################ Serialization key ########################
buffer.clear();
ObjectWrap objW = new ObjectWrap(key);
Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
// ################ Serialization key ########################
obj.add(ByteBuffer.wrap(k));
}
super.hashAdd(gvName, obj,idLocalize);
}
示例5: containsValue
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* Returns <tt>true</tt> if this map maps one or more keys to the
* specified value.
*
* @param value value whose presence in this map is to be tested
* @return <tt>true</tt> if this map maps one or more keys to the
* specified value
*/
public boolean containsValue(Object value) {
Set table = super.getHashSet(gvName,idLocalize);
for(Object k:table){
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
ObjectWrap obj = scow.newMessage();
ProtobufIOUtil.mergeFrom(((ByteBuffer)k).getArray(), obj, scow);
K key = (K)obj.getobj();
Object valueGV = DEFAULT_JCL.getValue(key.toString()+"�Map�"+gvName).getCorrectResult();
if(value.equals(valueGV)){
return true;
}
}
return false;
}
示例6: nextEntry
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
final Entry<K,V> nextEntry() {
current = queue.poll();
double pag = size/(queue.size()+size);
if(((pag>0.4) || (gvList.size()==1)) && (intGvList.hasNext())){
java.util.Map.Entry<Integer, JCL_message_generic> entHost = intGvList.next();
ticket.add(JCLHashMapPacu.super.getHashValues(queue, entHost.getValue(), entHost.getKey()));
}
size++;
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
ObjectWrap obj = scow.newMessage();
ProtobufIOUtil.mergeFrom(((ByteBuffer)current.getKey()).getArray(), obj, scow);
K key = (K)obj.getobj();
ProtobufIOUtil.mergeFrom((byte[])current.getValue(), obj, scow);
V value = (V)obj.getobj();
return new implementations.util.Entry<K, V>(key,value);
// return current;
}
示例7: put
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* Associates the specified value with the specified key in this map.
* If the map previously contained a mapping for the key, the old
* value is replaced.
*
* @param key key with which the specified value is to be associated
* @param value value to be associated with the specified key
* @return the previous value associated with <tt>key</tt>, or
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
*/
public V put(K key, V value){
Object oldValue = null;
if ((key != null) && ((oldValue = super.hashPut((key.toString()+"¬Map¬"+gvName), value))!=null)){
// ################ Serialization key ########################
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
ObjectWrap objW = new ObjectWrap(key);
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
// ################ Serialization key ########################
super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
}else{
System.out.println("Null key or fault in put<K,V> on cluster!");
}
return (V)oldValue;
}
示例8: putUnlock
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* Associates the specified value with the specified key in this map.
* If the map previously contained a mapping for the key, the old
* value is replaced.
*
* @param key key with which the specified value is to be associated
* @param value value to be associated with the specified key
* @return the previous value associated with <tt>key</tt>, or
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
*/
public V putUnlock(K key, V value){
V oldValue = null;
if (key != null){
if(DEFAULT_JCL.containsGlobalVar(key.toString()+"¬Map¬"+gvName)){
oldValue = (V) DEFAULT_JCL.getValue(key.toString()+"¬Map¬"+gvName).getCorrectResult();
DEFAULT_JCL.setValueUnlocking((key.toString()+"¬Map¬"+gvName), value);
}else if (DEFAULT_JCL.instantiateGlobalVar((key.toString()+"¬Map¬"+gvName), value)){
// ################ Serialization key ########################
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
ObjectWrap objW = new ObjectWrap(key);
Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
// ################ Serialization key ########################
super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
}
}else{
System.out.println("Can't put<K,V> with null key!");
}
return (oldValue == null ? null : oldValue);
}
示例9: putAll
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* Copies all of the mappings from the specified map to this map.
* These mappings will replace any mappings that this map had for
* any of the keys currently in the specified map.
*
* @param m mappings to be stored in this map
* @throws NullPointerException if the specified map is null
*/
public void putAll(Map<? extends K, ? extends V> m) {
int numKeysToBeAdded = m.size();
if (numKeysToBeAdded == 0)
return;
super.instantiateBin((Object)m.entrySet(), this.gvName);
List<Object> obj = new ArrayList<Object>();
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
for(K key:m.keySet()){
// ################ Serialization key ########################
buffer.clear();
ObjectWrap objW = new ObjectWrap(key);
Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
// ################ Serialization key ########################
obj.add(ByteBuffer.wrap(k));
}
super.hashAdd(gvName, obj,idLocalize);
}
示例10: containsValue
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
/**
* Returns <tt>true</tt> if this map maps one or more keys to the
* specified value.
*
* @param value value whose presence in this map is to be tested
* @return <tt>true</tt> if this map maps one or more keys to the
* specified value
*/
public boolean containsValue(Object value) {
Set table = super.getHashSet(gvName,idLocalize);
for(Object k:table){
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
ObjectWrap obj = scow.newMessage();
ProtobufIOUtil.mergeFrom(((ByteBuffer)k).getArray(), obj, scow);
K key = (K)obj.getobj();
Object valueGV = DEFAULT_JCL.getValue(key.toString()+"¬Map¬"+gvName).getCorrectResult();
if(value.equals(valueGV)){
return true;
}
}
return false;
}
示例11: nextEntry
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
final Entry<K,V> nextEntry() {
current = queue.poll();
double pag = size/(queue.size()+size);
if(((pag>0.4) || (gvList.size()==1)) && (intGvList.hasNext())){
java.util.Map.Entry<Integer, JCL_message_generic> entHost = intGvList.next();
ticket.add(JCLHashMapPacu.super.getHashValues(queue, entHost.getValue(), entHost.getKey()));
}
size++;
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
ObjectWrap obj = scow.newMessage();
ProtobufIOUtil.mergeFrom(((ByteBuffer)current.getKey()).getArray(), obj, scow);
K key = (K)obj.getobj();
ProtobufIOUtil.mergeFrom((byte[])current.getValue(), obj, scow);
V value = (V)obj.getobj();
return new implementations.util.Entry<K, V>(key,value);
// return current;
}
示例12: getData
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
public byte[] getData () {
byte[] rtnData = null;
if (rawData) {
return data;
} else {
//auto-serialize
LinkedBuffer buffer = getMessageBuffer ();
Schema<MessageT> schema = (Schema<MessageT>) RuntimeSchema.getSchema (getClass ());
MessageT message = (MessageT) this;
try {
rtnData = ProtostuffIOUtil.toByteArray (message, schema, buffer);
} finally {
buffer.clear ();
}
}
return rtnData;
}
示例13: toString
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
@Override
public String toString () {
if (rawData) {
return Arrays.toString (data);
} else {
//auto-serialize
StringWriter writer = new StringWriter ();
Schema<MessageT> schema = (Schema<MessageT>) RuntimeSchema.getSchema (getClass ());
MessageT message = (MessageT) this;
try {
JsonIOUtil.writeTo (writer, message, schema, false);
} catch (IOException ex) {
ex.printStackTrace ();
}
return writer.toString ();
}
}
示例14: testFooStreamed
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
public void testFooStreamed() throws Exception
{
Schema<Foo> schema = RuntimeSchema.getSchema(Foo.class);
Foo fooCompare = foo;
Foo dfoo = new Foo();
ByteArrayOutputStream out = new ByteArrayOutputStream();
LinkedBuffer buffer = buf();
try
{
JsonXIOUtil.writeTo(out, fooCompare, schema, true, buffer);
}
finally
{
buffer.clear();
}
byte[] data = out.toByteArray();
JsonIOUtil.mergeFrom(data, dfoo, schema, true);
SerializableObjects.assertEquals(fooCompare, dfoo);
}
示例15: testBarStreamed
import io.protostuff.runtime.RuntimeSchema; //导入依赖的package包/类
public void testBarStreamed() throws Exception
{
Schema<Bar> schema = RuntimeSchema.getSchema(Bar.class);
for (Bar barCompare : new Bar[] { bar, negativeBar })
{
Bar dbar = new Bar();
ByteArrayOutputStream out = new ByteArrayOutputStream();
LinkedBuffer buffer = buf();
try
{
JsonXIOUtil.writeTo(out, barCompare, schema, true, buffer);
}
finally
{
buffer.clear();
}
byte[] data = out.toByteArray();
JsonIOUtil.mergeFrom(data, dbar, schema, true);
SerializableObjects.assertEquals(barCompare, dbar);
}
}