1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.event;
14 import java.util.UUID;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.WriteRequest;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.service.VirtualGraphSupport;
22 import org.simantics.event.ontology.EventResource;
23 import org.simantics.event.writer.EventSourceResolver;
24 import org.simantics.event.writer.EventWriteTask;
25 import org.simantics.event.writer.EventWriterJob;
26 import org.simantics.layer0.Layer0;
29 * @author Tuukka Lehtonen
31 public class EventSupport {
33 private Resource model;
35 private EventSourceResolver.Filter filter;
37 @SuppressWarnings("unused")
38 private Resource eventLog;
40 private EventWriterJob writer;
41 private EventSourceResolver resolver;
43 public EventSupport(Resource model, Resource run, EventSourceResolver.Filter filter) {
49 public Resource initialize(WriteGraph graph) throws DatabaseException {
50 Layer0 L0 = Layer0.getInstance(graph);
51 final EventResource EVENT = EventResource.getInstance(graph);
53 Resource log = graph.newResource();
55 graph.claim(log, L0.InstanceOf, null, EVENT.EventLog);
56 graph.claimLiteral(log, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING);
57 graph.claim(model, EVENT.HasEventLog, log);
58 graph.claim(model, L0.ConsistsOf, log);
60 // Switch write to graph of run resource
61 final Resource _log = log;
62 VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);
63 graph.syncRequest(new WriteRequest( support.getGraph(graph, run) ) {
65 public void perform(WriteGraph graph) throws DatabaseException {
66 graph.claim(_log, EVENT.HasEventProducer, run);
70 // Start event writer & resolver services
71 this.resolver = new EventSourceResolver(graph.getProvider(), log, filter);
72 this.writer = new EventWriterJob(graph.getProvider(), log, this.resolver);
73 this.resolver.schedule();
78 public void queue(EventWriteTask task) {
79 EventWriterJob w = writer;
84 public void dispose() {
89 if (resolver != null) {