private C collectionFromWire() { C c = factory.get(); @SuppressWarnings("ConstantConditions") final ValueIn valueIn = ((Wire) outWire).getValueIn(); while (valueIn.hasNextSequenceItem()) { c.add(fromWire.apply(valueIn)); } return c; }
@Override public void readMarshallable(WireIn wire) throws IllegalStateException { @SuppressWarnings("ConstantConditions") final Bytes<?> outBytes = outWire.bytes(); try { final StringBuilder eventName = Wires.acquireStringBuilder(); @SuppressWarnings("ConstantConditions") final ValueIn valueIn = inWire.readEventName(eventName); outWire.writeDocument( true, w -> w.writeEventName(CoreFields.tid).int64(CollectionWireHandler.this.tid)); outWire.writeDocument( false, out -> { // note : remove on the key-set returns a boolean and on the map returns the // old value if (EventId.remove.contentEquals(eventName)) { outWire .write(CoreFields.reply) .bool(underlyingCollection.remove(fromWire.apply(valueIn))); return; } // note : remove on the key-set returns a boolean and on the map returns the // old value if (EventId.iterator.contentEquals(eventName)) { final ValueOut valueOut = out.writeEventName(CoreFields.reply); valueOut.sequence(v -> underlyingCollection.forEach(e -> toWire.accept(v, e))); return; } if (EventId.numberOfSegments.contentEquals(eventName)) { outWire.write(CoreFields.reply).int32(1); return; } if (EventId.isEmpty.contentEquals(eventName)) { outWire.write(CoreFields.reply).bool(underlyingCollection.isEmpty()); return; } if (EventId.size.contentEquals(eventName)) { outWire.write(CoreFields.reply).int32(underlyingCollection.size()); return; } if (EventId.clear.contentEquals(eventName)) { underlyingCollection.clear(); return; } if (EventId.contains.contentEquals(eventName)) { outWire .write(CoreFields.reply) .bool(underlyingCollection.contains(fromWire.apply(valueIn))); return; } if (EventId.add.contentEquals(eventName)) { outWire .write(CoreFields.reply) .bool(underlyingCollection.add(fromWire.apply(valueIn))); return; } if (EventId.remove.contentEquals(eventName)) { outWire .write(CoreFields.reply) .bool(underlyingCollection.remove(fromWire.apply(valueIn))); return; } if (EventId.containsAll.contentEquals(eventName)) { outWire .write(CoreFields.reply) .bool(underlyingCollection.remove(collectionFromWire())); return; } if (EventId.addAll.contentEquals(eventName)) { outWire .write(CoreFields.reply) .bool(underlyingCollection.addAll(collectionFromWire())); return; } if (EventId.removeAll.contentEquals(eventName)) { outWire .write(CoreFields.reply) .bool(underlyingCollection.removeAll(collectionFromWire())); return; } if (EventId.retainAll.contentEquals(eventName)) { outWire .write(CoreFields.reply) .bool(underlyingCollection.retainAll(collectionFromWire())); return; } throw new IllegalStateException("unsupported event=" + eventName); }); } catch (Exception e) { LOG.error("", e); } finally { if (YamlLogging.showServerWrites) { long len = outBytes.writePosition(); if (len >= SIZE_OF_SIZE) { String s = Wires.fromSizePrefixedBlobs(outBytes); LOG.info("server writes:\n\n" + s); } } } }