Search in sources :

Example 1 with EventHub

use of com.baidu.hugegraph.event.EventHub in project incubator-hugegraph by apache.

the class CachedSchemaTransaction method listenChanges.

private void listenChanges() {
    // Listen store event: "store.init", "store.clear", ...
    Set<String> storeEvents = ImmutableSet.of(Events.STORE_INIT, Events.STORE_CLEAR, Events.STORE_TRUNCATE);
    this.storeEventListener = event -> {
        if (storeEvents.contains(event.name())) {
            LOG.debug("Graph {} clear schema cache on event '{}'", this.graph(), event.name());
            this.clearCache(true);
            return true;
        }
        return false;
    };
    this.store().provider().listen(this.storeEventListener);
    // Listen cache event: "cache"(invalid cache item)
    this.cacheEventListener = event -> {
        LOG.debug("Graph {} received schema cache event: {}", this.graph(), event);
        Object[] args = event.args();
        E.checkArgument(args.length > 0 && args[0] instanceof String, "Expect event action argument");
        if (Cache.ACTION_INVALID.equals(args[0])) {
            event.checkArgs(String.class, HugeType.class, Id.class);
            HugeType type = (HugeType) args[1];
            Id id = (Id) args[2];
            this.invalidateCache(type, id);
            this.resetCachedAll(type);
            return true;
        } else if (Cache.ACTION_CLEAR.equals(args[0])) {
            event.checkArgs(String.class, HugeType.class);
            this.clearCache(false);
            return true;
        }
        return false;
    };
    EventHub schemaEventHub = this.params().schemaEventHub();
    if (!schemaEventHub.containsListener(Events.CACHE)) {
        schemaEventHub.listen(Events.CACHE, this.cacheEventListener);
    }
}
Also used : EventHub(com.baidu.hugegraph.event.EventHub) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

Example 2 with EventHub

use of com.baidu.hugegraph.event.EventHub in project incubator-hugegraph by apache.

the class HugeGremlinServer method start.

public static GremlinServer start(String conf, String graphsDir, EventHub hub) throws Exception {
    // Start GremlinServer with inject traversal source
    LOG.info(GremlinServer.getHeader());
    final Settings settings;
    try {
        settings = Settings.read(conf);
    } catch (Exception e) {
        LOG.error("Can't found the configuration file at '{}' or " + "being parsed properly. [{}]", conf, e.getMessage());
        throw e;
    }
    // Scan graph confs and inject into gremlin server context
    E.checkState(settings.graphs != null, "The GremlinServer's settings.graphs is null");
    settings.graphs.putAll(ConfigUtil.scanGraphsDir(graphsDir));
    LOG.info("Configuring Gremlin Server from {}", conf);
    ContextGremlinServer server = new ContextGremlinServer(settings, hub);
    // Inject customized traversal source
    server.injectTraversalSource();
    server.start().exceptionally(t -> {
        LOG.error("Gremlin Server was unable to start and will " + "shutdown now: {}", t.getMessage());
        server.stop().join();
        throw new HugeException("Failed to start Gremlin Server");
    }).join();
    return server;
}
Also used : HugeException(com.baidu.hugegraph.HugeException) ContextGremlinServer(com.baidu.hugegraph.auth.ContextGremlinServer) Log(com.baidu.hugegraph.util.Log) Logger(org.slf4j.Logger) ConfigUtil(com.baidu.hugegraph.util.ConfigUtil) GremlinServer(org.apache.tinkerpop.gremlin.server.GremlinServer) Settings(org.apache.tinkerpop.gremlin.server.Settings) EventHub(com.baidu.hugegraph.event.EventHub) E(com.baidu.hugegraph.util.E) ContextGremlinServer(com.baidu.hugegraph.auth.ContextGremlinServer) HugeException(com.baidu.hugegraph.HugeException) Settings(org.apache.tinkerpop.gremlin.server.Settings) HugeException(com.baidu.hugegraph.HugeException)

Example 3 with EventHub

use of com.baidu.hugegraph.event.EventHub in project hugegraph-common by hugegraph.

the class EventHubTest method setup.

@Before
public void setup() {
    this.eventHub = new EventHub("test");
    Assert.assertEquals("test", this.eventHub.name());
}
Also used : EventHub(com.baidu.hugegraph.event.EventHub) Before(org.junit.Before)

Example 4 with EventHub

use of com.baidu.hugegraph.event.EventHub in project incubator-hugegraph by apache.

the class CachedSchemaTransaction method unlistenChanges.

private void unlistenChanges() {
    // Unlisten store event
    this.store().provider().unlisten(this.storeEventListener);
    // Unlisten cache event
    EventHub schemaEventHub = this.params().schemaEventHub();
    schemaEventHub.unlisten(Events.CACHE, this.cacheEventListener);
}
Also used : EventHub(com.baidu.hugegraph.event.EventHub)

Example 5 with EventHub

use of com.baidu.hugegraph.event.EventHub in project incubator-hugegraph by apache.

the class CachedSchemaTransaction method notifyChanges.

private final void notifyChanges(String action, HugeType type, Id id) {
    EventHub graphEventHub = this.params().schemaEventHub();
    graphEventHub.notify(Events.CACHE, action, type, id);
}
Also used : EventHub(com.baidu.hugegraph.event.EventHub)

Aggregations

EventHub (com.baidu.hugegraph.event.EventHub)8 Id (com.baidu.hugegraph.backend.id.Id)2 HugeType (com.baidu.hugegraph.type.HugeType)2 HugeException (com.baidu.hugegraph.HugeException)1 ContextGremlinServer (com.baidu.hugegraph.auth.ContextGremlinServer)1 QueryId (com.baidu.hugegraph.backend.cache.CachedBackendStore.QueryId)1 ConfigUtil (com.baidu.hugegraph.util.ConfigUtil)1 E (com.baidu.hugegraph.util.E)1 Log (com.baidu.hugegraph.util.Log)1 GremlinServer (org.apache.tinkerpop.gremlin.server.GremlinServer)1 Settings (org.apache.tinkerpop.gremlin.server.Settings)1 Before (org.junit.Before)1 Logger (org.slf4j.Logger)1