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);
}
}
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;
}
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());
}
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);
}
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);
}
Aggregations