@Override public void registerSubscriber( @NotNull RequestContext rc, @NotNull Subscriber subscriber, @NotNull Filter filter) { Class eClass = rc.type(); if (eClass == Entry.class || eClass == MapEvent.class) registerSubscriber0(rc, subscriber, filter); else registerKeySubscriber(rc, subscriber, filter); }
@Override public void registerKeySubscriber( @NotNull RequestContext rc, @NotNull Subscriber<K> subscriber, @NotNull Filter<K> filter) { addToStats("keySubscription"); final Boolean bootstrap = rc.bootstrap(); final Subscriber<K> sub = subscriber(subscriber, filter); keySubscribers.add(sub); if (bootstrap != Boolean.FALSE && kvStore != null) { try { for (int i = 0; i < kvStore.segments(); i++) kvStore.keysFor(i, sub::onMessage); if (TRUE.equals(rc.endSubscriptionAfterBootstrap())) { sub.onEndOfSubscription(); keySubscribers.remove(sub); } } catch (InvalidSubscriberException e) { keySubscribers.remove(sub); } } }
@Override public void registerTopicSubscriber( @NotNull RequestContext rc, @NotNull TopicSubscriber subscriber) { addToStats("topicSubscription"); Boolean bootstrap = rc.bootstrap(); topicSubscribers.add((TopicSubscriber<K, V>) subscriber); if (bootstrap != Boolean.FALSE && kvStore != null) { try { for (int i = 0; i < kvStore.segments(); i++) kvStore.entriesFor(i, e -> subscriber.onMessage(e.getKey(), e.getValue())); } catch (InvalidSubscriberException dontAdd) { topicSubscribers.remove(subscriber); } } }
private void registerSubscriber0( @NotNull RequestContext rc, @NotNull Subscriber<MapEvent<K, V>> subscriber, @NotNull Filter<MapEvent<K, V>> filter) { addToStats("subscription"); final Subscriber<MapEvent<K, V>> sub = subscriber(subscriber, filter); this.subscribers.add(sub); Boolean bootstrap = rc.bootstrap(); if (bootstrap != Boolean.FALSE && kvStore != null) { try { for (int i = 0; i < kvStore.segments(); i++) kvStore.entriesFor(i, sub::onMessage); if (TRUE.equals(rc.endSubscriptionAfterBootstrap())) { sub.onEndOfSubscription(); LOG.info("onEndOfSubscription"); this.subscribers.remove(sub); } } catch (InvalidSubscriberException e) { this.subscribers.remove(sub); } } }
@NotNull private ReadMarshallable wireInConsumer() { return (wire) -> { long startWritePosition = outWire.bytes().writePosition(); // if true the next data message will be a system message isSystemMessage = wire.bytes().readRemaining() == 0; if (isSystemMessage) { if (LOG.isDebugEnabled()) LOG.debug("received system-meta-data"); return; } try { readCsp(wire); readTid(wire); } catch (Throwable t) { Jvm.rethrow(t); } try { if (hasCspChanged(cspText)) { if (LOG.isDebugEnabled()) LOG.debug("received meta-data:\n" + wire.bytes().toHexString()); requestContext = requestContextInterner.intern(cspText); viewType = requestContext.viewType(); if (viewType == null) { if (LOG.isDebugEnabled()) LOG.debug("received system-meta-data"); isSystemMessage = true; return; } view = this.assetTree.acquireView(requestContext); if (viewType == MapView.class || viewType == EntrySetView.class || viewType == ValuesCollection.class || viewType == KeySetView.class || viewType == ObjectKVSSubscription.class || viewType == TopicPublisher.class || viewType == Publisher.class || viewType == Reference.class || viewType == TopologySubscription.class || viewType == Replication.class || viewType == Heartbeat.class) { // default to string type if not provided final Class type = requestContext.keyType() == null ? String.class : requestContext.keyType(); final Class type2 = requestContext.valueType() == null ? String.class : requestContext.valueType(); wireAdapter = new GenericWireAdapter(type, type2); } else throw new UnsupportedOperationException("unsupported view type"); } } catch (Throwable e) { LOG.error("", e); outWire.bytes().writePosition(startWritePosition); outWire.writeDocument(true, w -> w.writeEventName(CoreFields.tid).int64(tid)); outWire.writeDocument(false, out -> out.writeEventName(() -> "exception").throwable(e)); logYamlToStandardOut(outWire); rethrow(e); } }; }
public MapKVSSubscription(@NotNull RequestContext requestContext, @NotNull Asset asset) { this(requestContext.viewType(), asset); }