Java Code Examples for org.jgroups.util.Util#objectFromStream()
The following examples show how to use
org.jgroups.util.Util#objectFromStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplicatedStateMachine.java From jgroups-raft with Apache License 2.0 | 6 votes |
@Override public byte[] apply(byte[] data, int offset, int length) throws Exception { ByteArrayDataInputStream in=new ByteArrayDataInputStream(data, offset, length); byte command=in.readByte(); switch(command) { case PUT: K key=Util.objectFromStream(in); V val=Util.objectFromStream(in); V old_val; synchronized(map) { old_val=map.put(key, val); } notifyPut(key, val, old_val); return old_val == null? null : Util.objectToByteBuffer(old_val); case REMOVE: key=Util.objectFromStream(in); synchronized(map) { old_val=map.remove(key); } notifyRemove(key, old_val); return old_val == null? null : Util.objectToByteBuffer(old_val); default: throw new IllegalArgumentException("command " + command + " is unknown"); } }
Example 2
Source File: ReplicatedStateMachine.java From jgroups-raft with Apache License 2.0 | 5 votes |
@Override public void readContentFrom(DataInput in) throws Exception { int size=Bits.readInt(in); Map<K,V> tmp=new HashMap<>(size); for(int i=0; i < size; i++) { K key=Util.objectFromStream(in); V val=Util.objectFromStream(in); tmp.put(key, val); } synchronized(map) { map.putAll(tmp); } }
Example 3
Source File: JGroupsMessenger.java From tutorials with MIT License | 5 votes |
@Override public void setState(InputStream input) { // NOTE: since we know that incrementing the count and transferring the state // is done inside the JChannel's thread, we don't have to worry about synchronizing // messageCount. For production code it should be synchronized! try { // Deserialize messageCount = Util.objectFromStream(new DataInputStream(input)); } catch (Exception e) { System.out.println("Error deserialing state!"); } System.out.println(messageCount + " is the current messagecount."); }