-/*******************************************************************************\r
- * Copyright (c) 2012 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Semantum Oy - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.event;\r
-\r
-import java.util.UUID;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.VirtualGraphSupport;\r
-import org.simantics.event.ontology.EventResource;\r
-import org.simantics.event.writer.EventSourceResolver;\r
-import org.simantics.event.writer.EventWriteTask;\r
-import org.simantics.event.writer.EventWriterJob;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class EventSupport {\r
-\r
- private Resource model;\r
- private Resource run;\r
- private EventSourceResolver.Filter filter;\r
-\r
- @SuppressWarnings("unused")\r
- private Resource eventLog;\r
-\r
- private EventWriterJob writer;\r
- private EventSourceResolver resolver;\r
-\r
- public EventSupport(Resource model, Resource run, EventSourceResolver.Filter filter) {\r
- this.model = model;\r
- this.run = run;\r
- this.filter = filter;\r
- }\r
-\r
- public Resource initialize(WriteGraph graph) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- final EventResource EVENT = EventResource.getInstance(graph);\r
-\r
- Resource log = graph.newResource();\r
- this.eventLog = log;\r
- graph.claim(log, L0.InstanceOf, null, EVENT.EventLog);\r
- graph.claimLiteral(log, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING);\r
- graph.claim(model, EVENT.HasEventLog, log);\r
- graph.claim(model, L0.ConsistsOf, log);\r
-\r
- // Switch write to graph of run resource\r
- final Resource _log = log;\r
- VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);\r
- graph.syncRequest(new WriteRequest( support.getGraph(graph, run) ) {\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- graph.claim(_log, EVENT.HasEventProducer, run);\r
- }\r
- });\r
-\r
- // Start event writer & resolver services\r
- this.resolver = new EventSourceResolver(graph.getProvider(), log, filter);\r
- this.writer = new EventWriterJob(graph.getProvider(), log, this.resolver);\r
- this.resolver.schedule();\r
-\r
- return log;\r
- }\r
-\r
- public void queue(EventWriteTask task) {\r
- EventWriterJob w = writer;\r
- if (w != null)\r
- w.queue(task);\r
- }\r
-\r
- public void dispose() {\r
- if (writer != null) {\r
- writer.dispose();\r
- writer = null;\r
- }\r
- if (resolver != null) {\r
- resolver.dispose();\r
- resolver = null;\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.event;
+
+import java.util.UUID;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.VirtualGraphSupport;
+import org.simantics.event.ontology.EventResource;
+import org.simantics.event.writer.EventSourceResolver;
+import org.simantics.event.writer.EventWriteTask;
+import org.simantics.event.writer.EventWriterJob;
+import org.simantics.layer0.Layer0;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class EventSupport {
+
+ private Resource model;
+ private Resource run;
+ private EventSourceResolver.Filter filter;
+
+ @SuppressWarnings("unused")
+ private Resource eventLog;
+
+ private EventWriterJob writer;
+ private EventSourceResolver resolver;
+
+ public EventSupport(Resource model, Resource run, EventSourceResolver.Filter filter) {
+ this.model = model;
+ this.run = run;
+ this.filter = filter;
+ }
+
+ public Resource initialize(WriteGraph graph) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ final EventResource EVENT = EventResource.getInstance(graph);
+
+ Resource log = graph.newResource();
+ this.eventLog = log;
+ graph.claim(log, L0.InstanceOf, null, EVENT.EventLog);
+ graph.claimLiteral(log, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING);
+ graph.claim(model, EVENT.HasEventLog, log);
+ graph.claim(model, L0.ConsistsOf, log);
+
+ // Switch write to graph of run resource
+ final Resource _log = log;
+ VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);
+ graph.syncRequest(new WriteRequest( support.getGraph(graph, run) ) {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ graph.claim(_log, EVENT.HasEventProducer, run);
+ }
+ });
+
+ // Start event writer & resolver services
+ this.resolver = new EventSourceResolver(graph.getProvider(), log, filter);
+ this.writer = new EventWriterJob(graph.getProvider(), log, this.resolver);
+ this.resolver.schedule();
+
+ return log;
+ }
+
+ public void queue(EventWriteTask task) {
+ EventWriterJob w = writer;
+ if (w != null)
+ w.queue(task);
+ }
+
+ public void dispose() {
+ if (writer != null) {
+ writer.dispose();
+ writer = null;
+ }
+ if (resolver != null) {
+ resolver.dispose();
+ resolver = null;
+ }
+ }
+
+}