Also converts plenty of legacy Logger use to slf4j Logger.
gitlab #493
Change-Id: I0009ed3fd0c039312b1b9f74804cc2de2c39ec9a
import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.common.request.WriteRequest;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.CancelTransactionException;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.AsyncListener;
import org.simantics.db.request.WriteResult;
import org.simantics.utils.DataContainer;
import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class MergingGraphRequestProcessor implements AsyncRequestProcessor {
+ private static final Logger LOGGER = LoggerFactory.getLogger(MergingGraphRequestProcessor.class);
+
private static class SyncWriteRequestAdapter implements Write {
private Semaphore semaphore = new Semaphore(0);
try {
semaphore.acquire();
} catch (InterruptedException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("SyncWriteRequestAdapter interrupted", e);
}
}
try {
MergingGraphRequestProcessor.this.wait(transactionKeepalivePeriod);
} catch (InterruptedException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("MergedRead interrupted", e);
}
if (requestQueue.isEmpty())
break;
} catch(Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("MergedRead failed", t);
// if(currentRequest.second instanceof AsyncProcedure<?>) {
// ((AsyncProcedure<?>)currentRequest.second).exception(graph, t);
} else {
- try{
+ try {
if(currentRequest.second instanceof AsyncProcedure<?>) {
if(currentRequest.first instanceof AsyncRead) {
} catch(Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("MergedRead failed", t);
// if(currentRequest.second instanceof AsyncProcedure<?>) {
// ((AsyncProcedure<?>)currentRequest.second).exception(graph, t);
try {
MergingGraphRequestProcessor.this.wait(transactionKeepalivePeriod);
} catch (InterruptedException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("RunnerWriteGraphRequest interrupted", e);
}
if (requestQueue.isEmpty())
break;
graph.syncRequest(adapter);
if(callback != null) callback.accept(null);
} catch(Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("RunnerWriteGraphRequest failed", t);
if(callback != null) callback.accept(t);
}
else if(currentRequest.first instanceof DelayedWrite) graph.syncRequest((DelayedWrite)currentRequest.first);
if(callback != null) callback.accept(null);
} catch(Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("RunnerWriteGraphRequest failed", t);
if(callback != null) callback.accept(t);
}
Throwable t = throwable.get();
if(t != null) {
- Logger.defaultLogError(t);
+ LOGGER.error("syncRequest(AsyncMultiRead, AsyncMultiProcedure) failed", t);
throw new RuntimeException(t.getMessage());
}
Throwable t = throwable.get();
if(t != null) {
- Logger.defaultLogError(t);
+ LOGGER.error("syncRequest(AsyncRead, AsyncProcedure) failed", t);
throw new RuntimeException(t.getMessage());
}
@Override
public void exception(Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("asyncRequest(AsyncRead) failed", t);
}
});
Throwable t = throwable.get();
if(t != null) {
- Logger.defaultLogError(t);
+ LOGGER.error("syncRequest(AsyncRead) failed", t);
throw new RuntimeException(t.getMessage());
}
Throwable t = throwable.get();
if(t != null) {
- Logger.defaultLogError(t);
+ LOGGER.error("syncRequest(AsyncMultiRead) failed", t);
throw new RuntimeException(t.getMessage());
}
@Override
public void exception(Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("asyncRequest(Read) failed", t);
}
});
throw new UnsupportedOperationException();
}
+ @Override
+ public <T> T l0() {
+ return processor.l0();
+ }
+
}
public class ProcessorBase implements AsyncRequestProcessor {
+ @Override
+ public <T> T l0() {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public <T> void asyncRequest(AsyncMultiRead<T> request, AsyncMultiProcedure<T> procedure) {
throw new UnsupportedOperationException();
* @author Hannu Niemistö
*/
public class AdaptValue extends ResourceRead<Object> {
-
+
public AdaptValue(Resource resource) {
super(resource);
}
}
};
-
+
@Override
public Object perform(ReadGraph graph) throws DatabaseException {
- String uri = graph.getURI(resource);
- if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
+ Layer0 L0 = graph.l0();
+ if (L0.Functions_functionApplication.equalsResource(resource))
+ return functionApplication;
ComputationalValue ev = graph.adapt(resource, ComputationalValue.class);
return ev.getValue(graph, resource);
-
}
}
else return getTopLevelGraphStatic(impl.parentGraph);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T l0() {
+ return (T) processor.getL0();
+ }
+
}
return L0;
}
+ public Layer0 getL0() {
+ return L0;
+ }
+
public static ThreadLocal<Integer> thread = new ThreadLocal<Integer>() {
protected Integer initialValue() {
return -1;
*/
public abstract class ContextualRelatedValue implements ConverterComputationalValue {
- @SuppressWarnings("unchecked")
- @Override
- public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
- return (T) new FunctionImpl3<ReadGraph, Resource, Object, Object>() {
- @Override
- public Object apply(ReadGraph graph, Resource converter, Object context) {
- SCLContext sclContext = SCLContext.getCurrent();
- Object oldGraph = sclContext.get("graph");
- try {
- if (context instanceof Variable) {
- Variable variable = (Variable)context;
- try {
- Function1<Object,Object> fn = getFunction(graph, variable.getParent(graph).getRepresents(graph), variable.getRepresents(graph), variable.getPredicateResource(graph));
- sclContext.put("graph", graph);
- return fn.apply(variable);
- } catch (DatabaseException e) {
- throw new RuntimeDatabaseException(e);
- }
- } if (context instanceof Resource) {
- Resource resource = (Resource)context;
- try {
- // Here converter is the object and context is the subject
- Function1<Object,Object> fn = getFunction(graph, resource, converter, null);
- return fn.apply(resource);
- } catch (DatabaseException e) {
- throw new RuntimeDatabaseException(e);
- }
- } else {
- throw new IllegalStateException("Unknown context " + context);
+ private final FunctionImpl3<ReadGraph, Resource, Object, Object> function = new FunctionImpl3<ReadGraph, Resource, Object, Object>() {
+ @Override
+ public Object apply(ReadGraph graph, Resource converter, Object context) {
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ try {
+ if (context instanceof Variable) {
+ Variable variable = (Variable)context;
+ try {
+ Function1<Object,Object> fn = getFunction(graph, variable.getParent(graph).getRepresents(graph), variable.getRepresents(graph), variable.getPredicateResource(graph));
+ sclContext.put("graph", graph);
+ return fn.apply(variable);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ } if (context instanceof Resource) {
+ Resource resource = (Resource)context;
+ try {
+ // Here converter is the object and context is the subject
+ Function1<Object,Object> fn = getFunction(graph, resource, converter, null);
+ return fn.apply(resource);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
}
- } finally {
- sclContext.put("graph", oldGraph);
+ } else {
+ throw new IllegalStateException("Unknown context " + context);
}
+ } finally {
+ sclContext.put("graph", oldGraph);
}
- };
+ }
+ };
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
+ return (T) function;
}
}
import org.simantics.db.SessionReference;
import org.simantics.db.VirtualGraph;
import org.simantics.db.authentication.UserAuthenticationAgent;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.InvalidAuthenticationException;
import org.simantics.db.exception.InvalidUserException;
import org.simantics.db.impl.query.QueryProcessor;
import org.simantics.db.impl.query.QuerySupport;
import org.simantics.db.service.ServerInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
final public class SessionImplDb extends SessionImplSocket {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SessionImplDb.class);
+
/**
* Cached ServerInformation structure fetched from the server at connection
* time. It should never change during a single session and therefore it
try {
newId = cluster.createResource(clusterTranslator);
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("createResource failed", e);
return null;
}
return new ResourceImpl(resourceSupport, newId);
// clusterTable.dispose(); clusterTable = null;
// throw e;
} catch (Throwable e) {
- e.printStackTrace();
- Logger.defaultLogError("Unhandled error. See exception for details.", e);
+ LOGGER.error("Unhandled error. See exception for details.", e);
graphSession = null;
clusterTable.dispose(); clusterTable = null;
throw new Exception(e);
try {
getClusterTable().refresh(csid, this, clusterUID);
} catch (Throwable t) {
- Logger.defaultLogError("Refesh failed.", t);
+ LOGGER.error("refresh({}, {}) failed", thread, csid, t);
}
}
assert (null != writer);
} catch (Throwable t) {
if (!(t instanceof CancelTransactionException))
- Logger.defaultLogError("Write transaction caused an unexpected error, see exception.", t);
+ LOGGER.error("Write transaction caused an unexpected error, see exception.", t);
writeState.except(t);
} finally {
writer.asyncBarrier.dec();
// Log it first, just to be safe that the error is always logged.
if (!(e instanceof CancelTransactionException))
- Logger.defaultLogError("Write transaction caused an unexpected error, see exception.", e);
+ LOGGER.error("Write transaction caused an unexpected error, see exception.", e);
// writeState.getGraph().state.barrier.dec();
// writeState.getGraph().waitAsync(request);
if (t instanceof DatabaseException) callback.accept((DatabaseException) t);
else callback.accept(new DatabaseException(t));
} else
- Logger.defaultLogError("Unhandled exception", t);
+ LOGGER.error("Unhandled exception", t);
}
};
callback.exception(new DatabaseException(e));
state.stopWriteTransaction(clusterStream);
- Logger.defaultLogError("Write transaction caused an unexpected error, see exception.", e);
+ LOGGER.error("Write transaction caused an unexpected error, see exception.", e);
} finally {
if(throwable != null) {
throwable.set(th);
} else {
- Logger.defaultLogError("Unhandled exception", th);
+ LOGGER.error("Unhandled exception", th);
}
}
if(throwable != null) {
throwable.set(t);
} else {
- Logger.defaultLogError("Unhandled exception", t);
+ LOGGER.error("Unhandled exception", t);
}
try {
if(throwable != null) {
throwable.set(t2);
} else {
- Logger.defaultLogError("Unhandled exception", t2);
+ LOGGER.error("Unhandled exception", t2);
}
}
*/
@SuppressWarnings("unchecked")
@Override
- public synchronized <T> T peekService(Class<T> api) {
-
- if(serviceKey1 == api) {
- return (T)service1;
- } else if (serviceKey2 == api) {
- // Promote this key
- Object result = service2;
- service2 = service1;
- serviceKey2 = serviceKey1;
- service1 = result;
- serviceKey1 = api;
- return (T)result;
- }
+ public <T> T peekService(Class<T> api) {
+ if (Layer0.class == api)
+ return (T) L0;
- if (Layer0.class == api)
- return (T) L0;
- if (ServerInformation.class == api)
- return (T) getCachedServerInformation();
- else if (WriteGraphImpl.class == api)
- return (T) writeState.getGraph();
- else if (ClusterBuilder.class == api)
- return (T)new ClusterBuilderImpl(this, (WriteOnlySupport)writeState.getGraph().writeSupport);
- else if (ClusterBuilderFactory.class == api)
- return (T)new ClusterBuilderFactoryImpl(this);
+ synchronized (this) {
+ if (serviceKey1 == api) {
+ return (T) service1;
+ }
+ if (serviceKey2 == api) {
+ // Promote this key
+ Object result = service2;
+ service2 = service1;
+ serviceKey2 = serviceKey1;
+ service1 = result;
+ serviceKey1 = api;
+ return (T)result;
+ }
- service2 = service1;
- serviceKey2 = serviceKey1;
+ if (ServerInformation.class == api)
+ return (T) getCachedServerInformation();
+ else if (WriteGraphImpl.class == api)
+ return (T) writeState.getGraph();
+ else if (ClusterBuilder.class == api)
+ return (T)new ClusterBuilderImpl(this, (WriteOnlySupport)writeState.getGraph().writeSupport);
+ else if (ClusterBuilderFactory.class == api)
+ return (T)new ClusterBuilderFactoryImpl(this);
- service1 = serviceLocator.peekService(api);
- serviceKey1 = api;
+ service2 = service1;
+ serviceKey2 = serviceKey1;
- return (T)service1;
+ service1 = serviceLocator.peekService(api);
+ serviceKey1 = api;
+ return (T)service1;
+ }
}
/*
try {
h.valuesChanged(ctx);
} catch (Exception e) {
- Logger.defaultLogError("monitor handler notification produced the following exception", e);
+ LOGGER.error("monitor handler notification produced the following exception", e);
} catch (LinkageError e) {
- Logger.defaultLogError("monitor handler notification produced a linkage error", e);
+ LOGGER.error("monitor handler notification produced a linkage error", e);
}
}
}
state.setCombine(false);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T l0() {
+ return (T) L0;
+ }
+
}
import org.simantics.db.ServerI;
import org.simantics.db.VirtualGraph;
import org.simantics.db.authentication.UserAuthenticationAgent;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.InvalidAuthenticationException;
import org.simantics.db.exception.InvalidUserException;
import org.simantics.db.impl.VirtualGraphImpl;
import org.simantics.db.impl.query.QueryProcessor;
import org.simantics.db.service.ServerInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import fi.vtt.simantics.procore.BackdoorAuthenticator;
import fi.vtt.simantics.procore.ProCoreServerReference;
import fi.vtt.simantics.procore.SessionManagerSource;
public class SessionImplVirtual extends SessionImplSocket {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SessionImplVirtual.class);
+
protected VirtualGraphImpl virtualGraphImpl;
public SessionImplVirtual(UserAuthenticationAgent authAgent)
throws DatabaseException {
} catch (InvalidUserException e) {
throw e;
} catch (IOException e) {
- Logger.defaultLogError("I/O error. See exception for details.", e);
+ LOGGER.error("I/O error. See exception for details.", e);
graphSession = null;
throw new DatabaseException(e);
} catch (Throwable e) {
- e.printStackTrace();
- Logger.defaultLogError("Unhandled error. See exception for details.", e);
+ LOGGER.error("Unhandled error. See exception for details.", e);
graphSession = null;
throw new DatabaseException(e);
}
try {
return gs.getServerInformation();
} catch (DatabaseException e) {
- Logger.defaultLogError("Failed to get server info.", e);
+ LOGGER.error("Failed to get server info.", e);
return null;
}
}
import org.simantics.db.WriteGraph;
import org.simantics.db.common.MetadataUtils;
import org.simantics.db.common.exception.DebugException;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.ImmutableException;
import org.simantics.db.exception.ServiceException;
import org.simantics.db.request.WriteResult;
import org.simantics.db.request.WriteTraits;
import org.simantics.db.service.ByteReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class WriteSupportImpl implements WriteSupport {
+ private static final Logger LOGGER = LoggerFactory.getLogger(WriteSupportImpl.class);
+
final private SessionImplSocket session;
final private QueryProcessor queryProcessor;
final private State state;
try {
addSetValue(((ResourceImpl) resource).id, value, value.length);
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("writeOnly setValue({}, {}, byte[{}]) failed", provider, resource, value.length, e);
}
}
} else {
try {
addSetValue(((ResourceImpl) resource).id, value, value.length);
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("setValue({}, {}, byte[{}]) failed", provider, resource, value.length, e);
}
}
queryProcessor.releaseWrite(session.writeState.getGraph());
try {
cluster.removeValue(key, session.clusterTranslator);
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("denyValue({}, {}) failed", provider, resource, e);
return;
}
queryProcessor.updateValue(key);
if (null != c && c != cluster)
session.clusterTable.replaceCluster(c);
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("claimImpl({}, {}, {}) failed", subject, predicate, object, e);
throw new RuntimeException(e);
}
queryProcessor.updateStatements(subject, predicate);
if (null != c && c != cluster)
session.clusterTable.replaceCluster(c);
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("claimImpl2({}, {}, {}) failed", subject, predicate, object, e);
}
if (cluster.isWriteOnly())
return;
try {
cluster.denyRelation(subject, predicate, object, session.clusterTranslator);
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("removeStatement({}, {}, {}) failed", subject, predicate, object, e);
return false;
}
queryProcessor.updateStatements(subject, predicate);
* @see MergingGraphRequestProcessor
* @see AsyncRequestProcessor
*/
-public interface RequestProcessor extends RequestProcessorSpecific, ServiceLocator {
+public interface RequestProcessor extends RequestProcessorSpecific, ServiceLocator, ResourceLocator {
Resource getRootLibrary();
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2020 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.db;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.43.0
+ */
+public interface ResourceLocator {
+
+ /**
+ * Layer0 is an integral part of Simantics database modelling and for performance
+ * reasons deserves simplest possible access to its resource class.
+ *
+ * @return returns the internally cached
+ * <code>org.simantics.layer0.Layer0</code> instance
+ */
+ public <T> T l0();
+
+}