cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] 01/02: CAY-2519 Use NoopEventManager if SERVER_CONTEXTS_SYNC_PROPERTY is false
Date Fri, 07 Jun 2019 13:22:12 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch STABLE-4.0
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit bc5cf828a853ba83468e9a6fcaf9d60433be9f11
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Thu Feb 7 14:58:05 2019 +0300

    CAY-2519 Use NoopEventManager if SERVER_CONTEXTS_SYNC_PROPERTY is false
---
 RELEASE-NOTES.txt                                  | 12 +++-
 .../configuration/rop/client/ClientModule.java     |  8 ++-
 .../org/apache/cayenne/access/DataContext.java     | 10 ++-
 .../cayenne/configuration/server/ServerModule.java | 16 ++---
 .../apache/cayenne/event/EventManagerProvider.java | 44 ++++++++++++
 .../org/apache/cayenne/event/NoopEventManager.java | 81 ++++++++++++++++++++++
 6 files changed, 157 insertions(+), 14 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index a27c383..f462915 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -8,6 +8,17 @@ To browse individual bug reports check out project issue tracker:
 https://issues.apache.org/jira/browse/CAY
 
 ----------------------------------
+Release: 4.0.2
+Date:
+----------------------------------
+
+=======
+Changes/New Features:
+
+CAY-2517 EventManager: optimization of adding listeners
+CAY-2519 Use NoopEventManager if SERVER_CONTEXTS_SYNC_PROPERTY is false
+
+----------------------------------
 Release: 4.0.1
 Date: December 20, 2018
 ----------------------------------
@@ -20,7 +31,6 @@ CAY-2474 Modeler: swap buttons in dialog toolbar
 CAY-2475 Modeler: move inheritance icon to name column in objAttr table and objRel table
 CAY-2476 Modeler: Fixed wrong behaviour of code generation dialog
 CAY-2479 Modeler: update cgen dialog
-CAY-2517 EventManager: optimization of adding listeners
 
 Bug Fixes:
 
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
b/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
index 690ed2c..0a0553e 100644
--- a/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
+++ b/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
@@ -30,11 +30,13 @@ import org.apache.cayenne.configuration.server.ServerModule;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.MapBuilder;
 import org.apache.cayenne.di.Module;
-import org.apache.cayenne.event.DefaultEventManager;
 import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.event.EventManagerProvider;
 import org.apache.cayenne.remote.ClientConnection;
 import org.apache.cayenne.remote.RemoteService;
-import org.apache.cayenne.rop.*;
+import org.apache.cayenne.rop.HttpClientConnectionProvider;
+import org.apache.cayenne.rop.ProxyRemoteService;
+import org.apache.cayenne.rop.ROPSerializationService;
 import org.apache.cayenne.rop.http.ClientHessianSerializationServiceProvider;
 
 /**
@@ -87,7 +89,7 @@ public class ClientModule implements Module {
         binder.bind(ROPSerializationService.class).toProvider(ClientHessianSerializationServiceProvider.class);
         binder.bind(RemoteService.class).to(ProxyRemoteService.class);
         binder.bind(ClientConnection.class).toProvider(HttpClientConnectionProvider.class);
-        binder.bind(EventManager.class).to(DefaultEventManager.class);
+        binder.bind(EventManager.class).toProvider(EventManagerProvider.class);
         binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
         binder.bind(DataChannel.class).toProvider(ClientChannelProvider.class);
         binder.bind(QueryCache.class).toProvider(MapQueryCacheProvider.class);
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java b/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java
index bc80736..d430914 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/DataContext.java
@@ -44,6 +44,7 @@ import org.apache.cayenne.ResultIterator;
 import org.apache.cayenne.access.util.IteratedSelectObserver;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.event.NoopEventManager;
 import org.apache.cayenne.graph.ChildDiffLoader;
 import org.apache.cayenne.graph.CompoundDiff;
 import org.apache.cayenne.graph.GraphDiff;
@@ -53,7 +54,12 @@ import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.query.*;
+import org.apache.cayenne.query.EntityResultSegment;
+import org.apache.cayenne.query.MappedExec;
+import org.apache.cayenne.query.MappedSelect;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.QueryMetadata;
+import org.apache.cayenne.query.Select;
 import org.apache.cayenne.reflect.AttributeProperty;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.PropertyVisitor;
@@ -140,7 +146,7 @@ public class DataContext extends BaseContext {
 
         EventManager eventManager = channel.getEventManager();
 
-        if (eventManager != null) {
+        if (eventManager != null && !(eventManager instanceof NoopEventManager))
{
             mergeHandler = new DataContextMergeHandler(this);
 
             // listen to our channel events...
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
index 44b926a..ccc20ee 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
@@ -18,6 +18,9 @@
  ****************************************************************/
 package org.apache.cayenne.configuration.server;
 
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.DataChannelFilter;
 import org.apache.cayenne.access.DataDomain;
@@ -55,6 +58,7 @@ import org.apache.cayenne.access.types.TimeType;
 import org.apache.cayenne.access.types.TimestampType;
 import org.apache.cayenne.access.types.UUIDValueType;
 import org.apache.cayenne.access.types.UtilDateType;
+import org.apache.cayenne.access.types.ValueObjectType;
 import org.apache.cayenne.access.types.ValueObjectTypeRegistry;
 import org.apache.cayenne.access.types.VoidType;
 import org.apache.cayenne.ashwood.AshwoodEntitySorter;
@@ -97,14 +101,13 @@ import org.apache.cayenne.di.MapBuilder;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.spi.DefaultAdhocObjectFactory;
 import org.apache.cayenne.di.spi.DefaultClassLoaderManager;
-import org.apache.cayenne.event.DefaultEventManager;
-import org.apache.cayenne.event.NoopEventBridgeProvider;
 import org.apache.cayenne.event.EventBridge;
 import org.apache.cayenne.event.EventManager;
-import org.apache.cayenne.log.Slf4jJdbcEventLogger;
+import org.apache.cayenne.event.EventManagerProvider;
+import org.apache.cayenne.event.NoopEventBridgeProvider;
 import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.log.Slf4jJdbcEventLogger;
 import org.apache.cayenne.map.EntitySorter;
-import org.apache.cayenne.access.types.ValueObjectType;
 import org.apache.cayenne.resource.ClassLoaderResourceLocator;
 import org.apache.cayenne.resource.ResourceLocator;
 import org.apache.cayenne.tx.DefaultTransactionFactory;
@@ -114,9 +117,6 @@ import org.apache.cayenne.tx.TransactionFilter;
 import org.apache.cayenne.tx.TransactionManager;
 import org.apache.cayenne.velocity.VelocitySQLTemplateProcessor;
 
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-
 /**
  * A DI module containing all Cayenne server runtime configuration.
  *
@@ -341,7 +341,7 @@ public class ServerModule implements Module {
 
         binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
 
-        binder.bind(EventManager.class).to(DefaultEventManager.class);
+        binder.bind(EventManager.class).toProvider(EventManagerProvider.class);
 
         binder.bind(QueryCache.class).toProvider(MapQueryCacheProvider.class);
 
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/event/EventManagerProvider.java
b/cayenne-server/src/main/java/org/apache/cayenne/event/EventManagerProvider.java
new file mode 100644
index 0000000..ddf4360
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/event/EventManagerProvider.java
@@ -0,0 +1,44 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.event;
+
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.di.DIRuntimeException;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+
+/**
+ * @since 4.0.2
+ */
+public class EventManagerProvider implements Provider<EventManager> {
+
+    protected RuntimeProperties properties;
+
+    public EventManagerProvider(@Inject RuntimeProperties properties) {
+        this.properties = properties;
+    }
+
+    @Override
+    public EventManager get() throws DIRuntimeException {
+        boolean sync = properties.getBoolean(Constants.SERVER_CONTEXTS_SYNC_PROPERTY, true);
+
+        return sync ? new DefaultEventManager() : new NoopEventManager();
+    }
+}
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/event/NoopEventManager.java b/cayenne-server/src/main/java/org/apache/cayenne/event/NoopEventManager.java
new file mode 100644
index 0000000..db00c36
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/event/NoopEventManager.java
@@ -0,0 +1,81 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.event;
+
+import java.util.EventObject;
+
+/**
+ * @since 4.0.2
+ */
+public class NoopEventManager implements EventManager{
+    @Override
+    public boolean isSingleThreaded() {
+        return false;
+    }
+
+    @Override
+    public void addListener(Object listener, String methodName, Class<?> eventParameterClass,
EventSubject subject) {
+
+    }
+
+    @Override
+    public void addNonBlockingListener(Object listener, String methodName, Class<?>
eventParameterClass, EventSubject subject) {
+
+    }
+
+    @Override
+    public void addListener(Object listener, String methodName, Class<?> eventParameterClass,
EventSubject subject, Object sender) {
+
+    }
+
+    @Override
+    public void addNonBlockingListener(Object listener, String methodName, Class<?>
eventParameterClass, EventSubject subject, Object sender) {
+
+    }
+
+    @Override
+    public boolean removeListener(Object listener) {
+        return false;
+    }
+
+    @Override
+    public boolean removeAllListeners(EventSubject subject) {
+        return false;
+    }
+
+    @Override
+    public boolean removeListener(Object listener, EventSubject subject) {
+        return false;
+    }
+
+    @Override
+    public boolean removeListener(Object listener, EventSubject subject, Object sender) {
+        return false;
+    }
+
+    @Override
+    public void postEvent(EventObject event, EventSubject subject) {
+
+    }
+
+    @Override
+    public void postNonBlockingEvent(EventObject event, EventSubject subject) {
+
+    }
+}


Mime
View raw message