cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1586855 - in /cayenne/main/trunk: cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/ cayenne-server/src/main/java/org/apache/cayenne/event/ cayenne-server/src/main/java/org/apache/cayenne/remote/ cayenne-server/src/test/java/o...
Date Sat, 12 Apr 2014 12:13:31 GMT
Author: aadamchik
Date: Sat Apr 12 12:13:31 2014
New Revision: 1586855

URL: http://svn.apache.org/r1586855
Log:
CAY-1873 Move DataDomain cache configuration from the Modeler and into DI

preliminary refactoring/cleanup:
* properties in EventBridgeFactory must be Strings
* RemoteSession must not init EventBridge.. calling container should
  do it based on String parameters

Modified:
    cayenne/main/trunk/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/EventBridgeFactory.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JMSBridgeFactory.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JavaGroupsBridgeFactory.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/XMPPBridgeFactory.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/remote/RemoteSession.java
    cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeFactory.java

Modified: cayenne/main/trunk/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java?rev=1586855&r1=1586854&r2=1586855&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
(original)
+++ cayenne/main/trunk/cayenne-client/src/main/java/org/apache/cayenne/remote/hessian/HessianConnection.java
Sat Apr 12 12:13:31 2014
@@ -21,6 +21,7 @@ package org.apache.cayenne.remote.hessia
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.event.EventBridge;
+import org.apache.cayenne.event.EventBridgeFactory;
 import org.apache.cayenne.remote.BaseConnection;
 import org.apache.cayenne.remote.ClientMessage;
 import org.apache.cayenne.remote.RemoteService;
@@ -111,12 +112,38 @@ public class HessianConnection extends B
         return sharedSessionName;
     }
 
+    @Override
     public EventBridge getServerEventBridge() throws CayenneRuntimeException {
         if (session == null) {
             connect();
         }
 
-        return session.isServerEventsEnabled() ? session.createServerEventBridge() : null;
+        return createServerEventBridge(session);
+    }
+    
+    /**
+     * Creates an EventBridge that will listen for server events. Returns null if server
+     * events support is not configured in the descriptor.
+     * 
+     * @throws CayenneRuntimeException if EventBridge startup fails for any reason.
+     */
+    protected EventBridge createServerEventBridge(RemoteSession session) throws CayenneRuntimeException
{
+
+        if (!session.isServerEventsEnabled()) {
+            return null;
+        }
+
+        try {
+            EventBridgeFactory factory = (EventBridgeFactory) Class.forName(session.getEventBridgeFactory())
+                    .newInstance();
+
+            // must use "name", not the sessionId as an external subject for the
+            // event bridge
+            return factory.createEventBridge(RemoteSession.getSubjects(), session.getName(),
+                    session.getEventBridgeParameters());
+        } catch (Exception ex) {
+            throw new CayenneRuntimeException("Error creating EventBridge.", ex);
+        }
     }
 
     /**

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/EventBridgeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/EventBridgeFactory.java?rev=1586855&r1=1586854&r2=1586855&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/EventBridgeFactory.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/EventBridgeFactory.java
Sat Apr 12 12:13:31 2014
@@ -37,5 +37,5 @@ public interface EventBridgeFactory {
     EventBridge createEventBridge(
             Collection<EventSubject> localSubjects,
             String externalSubject,
-            Map<String, Object> properties);
+            Map<String, String> properties);
 }

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JMSBridgeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JMSBridgeFactory.java?rev=1586855&r1=1586854&r2=1586855&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JMSBridgeFactory.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JMSBridgeFactory.java
Sat Apr 12 12:13:31 2014
@@ -38,11 +38,11 @@ public class JMSBridgeFactory implements
     /**
      * @since 1.2
      */
-    public EventBridge createEventBridge(Collection<EventSubject> localSubjects, String
externalSubject, Map<String, Object> properties) {
+    public EventBridge createEventBridge(Collection<EventSubject> localSubjects, String
externalSubject, Map<String, String> properties) {
         JMSBridge bridge = new JMSBridge(localSubjects, externalSubject);
 
         // configure properties
-        String topicConnectionFactory = (String) properties
+        String topicConnectionFactory = properties
                 .get(TOPIC_CONNECTION_FACTORY_PROPERTY);
 
         bridge.setTopicConnectionFactoryName(topicConnectionFactory != null

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JavaGroupsBridgeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JavaGroupsBridgeFactory.java?rev=1586855&r1=1586854&r2=1586855&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JavaGroupsBridgeFactory.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/JavaGroupsBridgeFactory.java
Sat Apr 12 12:13:31 2014
@@ -51,14 +51,14 @@ public class JavaGroupsBridgeFactory imp
     /**
      * Creates a JavaGroupsBridge instance. Since JavaGroups is not shipped with Cayenne
      * and should be installed separately, a common misconfiguration problem may be the
-     * absense of JavaGroups jar file. This factory returns a dummy noop EventBridge, if
+     * absence of JavaGroups jar file. This factory returns a dummy noop EventBridge, if
      * this is the case. This would allow the application to continue to run, but without
      * remote notifications.
      */
     public EventBridge createEventBridge(
             Collection<EventSubject> localSubjects,
             String externalSubject,
-            Map<String, Object> properties) {
+            Map<String, String> properties) {
 
         try {
             // sniff JavaGroups presence
@@ -78,7 +78,7 @@ public class JavaGroupsBridgeFactory imp
     private EventBridge createJavaGroupsBridge(
             Collection<EventSubject> localSubjects,
             String externalSubject,
-            Map<String, Object> properties) {
+            Map<String, String> properties) {
 
         // create JavaGroupsBridge using reflection to avoid triggering
         // ClassNotFound exceptions due to JavaGroups absence.
@@ -91,9 +91,9 @@ public class JavaGroupsBridgeFactory imp
             Object bridge = c.newInstance(localSubjects, externalSubject);
 
             // configure properties
-            String multicastAddress = (String) properties.get(MCAST_ADDRESS_PROPERTY);
-            String multicastPort = (String) properties.get(MCAST_PORT_PROPERTY);
-            String configURL = (String) properties.get(JGROUPS_CONFIG_URL_PROPERTY);
+            String multicastAddress = properties.get(MCAST_ADDRESS_PROPERTY);
+            String multicastPort = properties.get(MCAST_PORT_PROPERTY);
+            String configURL = properties.get(JGROUPS_CONFIG_URL_PROPERTY);
 
             PropertyUtils.setProperty(bridge, "configURL", configURL);
             PropertyUtils.setProperty(
@@ -115,7 +115,7 @@ public class JavaGroupsBridgeFactory imp
     class NoopEventBridge extends EventBridge {
 
         public NoopEventBridge() {
-            super(Collections.EMPTY_SET, null);
+            super(Collections.<EventSubject>emptySet(), null);
         }
 
         @Override

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/XMPPBridgeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/XMPPBridgeFactory.java?rev=1586855&r1=1586854&r2=1586855&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/XMPPBridgeFactory.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/event/XMPPBridgeFactory.java
Sat Apr 12 12:13:31 2014
@@ -48,22 +48,23 @@ public class XMPPBridgeFactory implement
     public static final String XMPP_LOGIN_PROPERTY = "cayenne.XMPPBridge.xmppLogin";
     public static final String XMPP_PASSWORD_PROPERTY = "cayenne.XMPPBridge.xmppPassword";
 
+    @Override
     public EventBridge createEventBridge(
             Collection<EventSubject> localSubjects,
             String externalSubject,
-            Map<String, Object> properties) {
+            Map<String, String> properties) {
 
-        String chatService = (String) properties.get(XMPP_CHAT_SERVICE_PROPERTY);
-        String host = (String) properties.get(XMPP_HOST_PROPERTY);
+        String chatService = properties.get(XMPP_CHAT_SERVICE_PROPERTY);
+        String host = properties.get(XMPP_HOST_PROPERTY);
 
-        String loginId = (String) properties.get(XMPP_LOGIN_PROPERTY);
-        String password = (String) properties.get(XMPP_PASSWORD_PROPERTY);
+        String loginId = properties.get(XMPP_LOGIN_PROPERTY);
+        String password = properties.get(XMPP_PASSWORD_PROPERTY);
 
-        String secureConnectionString = (String) properties
+        String secureConnectionString = properties
                 .get(XMPP_SECURE_CONNECTION_PROPERTY);
         boolean secureConnection = "true".equalsIgnoreCase(secureConnectionString);
 
-        String portString = (String) properties.get(XMPP_PORT_PROPERTY);
+        String portString = properties.get(XMPP_PORT_PROPERTY);
         int port = -1;
         if (portString != null) {
 

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/remote/RemoteSession.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/remote/RemoteSession.java?rev=1586855&r1=1586854&r2=1586855&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/remote/RemoteSession.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/remote/RemoteSession.java
Sat Apr 12 12:13:31 2014
@@ -51,7 +51,7 @@ public class RemoteSession implements Se
     protected String sessionId;
 
     protected String eventBridgeFactory;
-    protected Map eventBridgeParameters;
+    protected Map<String, String> eventBridgeParameters;
 
     // private constructor used by hessian deserialization mechanism
     @SuppressWarnings("unused")
@@ -71,7 +71,7 @@ public class RemoteSession implements Se
      * is not null, session will support server events.
      */
     public RemoteSession(String sessionId, String eventBridgeFactory,
-            Map eventBridgeParameters) {
+            Map<String, String> eventBridgeParameters) {
 
         if (sessionId == null) {
             throw new IllegalArgumentException("Null sessionId");
@@ -114,7 +114,10 @@ public class RemoteSession implements Se
      * events support is not configured in the descriptor.
      * 
      * @throws CayenneRuntimeException if EventBridge startup fails for any reason.
+     * 
+     * @deprecated since 3.2. Factory creation should is handled by the client connection.
      */
+    @Deprecated
     public EventBridge createServerEventBridge() throws CayenneRuntimeException {
 
         if (!isServerEventsEnabled()) {
@@ -125,9 +128,9 @@ public class RemoteSession implements Se
             EventBridgeFactory factory = (EventBridgeFactory) Class.forName(
                     eventBridgeFactory).newInstance();
 
-            Map parameters = eventBridgeParameters != null
+            Map<String, String> parameters = eventBridgeParameters != null
                     ? eventBridgeParameters
-                    : Collections.EMPTY_MAP;
+                    : Collections.<String, String>emptyMap();
 
             // must use "name", not the sessionId as an external subject for the event
             // bridge
@@ -153,4 +156,22 @@ public class RemoteSession implements Se
 
         return builder.toString();
     }
+
+    public static Collection<EventSubject> getSubjects() {
+        return SUBJECTS;
+    }
+
+    /**
+     * @since 3.2
+     */
+    public String getEventBridgeFactory() {
+        return eventBridgeFactory;
+    }
+
+    /**
+     * @since 3.2
+     */
+    public Map<String, String> getEventBridgeParameters() {
+        return eventBridgeParameters != null ? eventBridgeParameters : Collections.<String,
String> emptyMap();
+    }
 }

Modified: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeFactory.java?rev=1586855&r1=1586854&r2=1586855&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeFactory.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/event/MockEventBridgeFactory.java
Sat Apr 12 12:13:31 2014
@@ -33,10 +33,11 @@ public class MockEventBridgeFactory impl
                 .convertToExternalSubject(localSubject), properties);
     }
 
+    @Override
     public EventBridge createEventBridge(
-            Collection localSubjects,
+            Collection<EventSubject> localSubjects,
             String externalSubject,
-            Map properties) {
+            Map<String, String> properties) {
 
         return new MockEventBridge(localSubjects, externalSubject, properties);
     }



Mime
View raw message