You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by dk...@apache.org on 2016/03/01 15:50:42 UTC
[4/9] cayenne git commit: Rename DefaultClientConnection to
HttpClientConnection, which is more informative.
Rename DefaultClientConnection to HttpClientConnection, which is more informative.
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/fadd1d1e
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/fadd1d1e
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/fadd1d1e
Branch: refs/heads/master
Commit: fadd1d1e73d883f949f4676f15a37cbe44a30ed1
Parents: c775dc4
Author: Dzmitry Kazimirchyk <dk...@gmail.com>
Authored: Sun Jan 24 23:26:19 2016 +0300
Committer: Dzmitry Kazimirchyk <dk...@gmail.com>
Committed: Tue Mar 1 14:10:19 2016 +0300
----------------------------------------------------------------------
.../configuration/rop/client/ClientModule.java | 2 +-
.../cayenne/rop/DefaultClientConnection.java | 126 -------------------
.../rop/DefaultClientConnectionProvider.java | 75 -----------
.../cayenne/rop/HttpClientConnection.java | 126 +++++++++++++++++++
.../rop/HttpClientConnectionProvider.java | 75 +++++++++++
.../cayenne/rop/http/HttpROPConnector.java | 6 +-
.../rop/client/ClientModuleTest.java | 4 +-
7 files changed, 207 insertions(+), 207 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fadd1d1e/cayenne-client/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
----------------------------------------------------------------------
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 a782ca3..b74d482 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
@@ -61,7 +61,7 @@ public class ClientModule implements Module {
binder.bind(ObjectContextFactory.class).to(CayenneContextFactory.class);
binder.bind(ROPSerializationService.class).toProvider(ClientHessianSerializationServiceProvider.class);
binder.bind(RemoteService.class).to(ProxyRemoteService.class);
- binder.bind(ClientConnection.class).toProvider(DefaultClientConnectionProvider.class);
+ binder.bind(ClientConnection.class).toProvider(HttpClientConnectionProvider.class);
binder.bind(EventManager.class).to(DefaultEventManager.class);
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
binder.bind(DataChannel.class).toProvider(ClientChannelProvider.class);
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fadd1d1e/cayenne-client/src/main/java/org/apache/cayenne/rop/DefaultClientConnection.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/rop/DefaultClientConnection.java b/cayenne-client/src/main/java/org/apache/cayenne/rop/DefaultClientConnection.java
deleted file mode 100644
index 00f21fc..0000000
--- a/cayenne-client/src/main/java/org/apache/cayenne/rop/DefaultClientConnection.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*****************************************************************
- * 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.rop;
-
-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;
-import org.apache.cayenne.remote.RemoteSession;
-
-public class DefaultClientConnection extends BaseConnection {
-
- private RemoteService remoteService;
- private RemoteSession session;
-
- private String sharedSessionName;
-
- public DefaultClientConnection(RemoteService remoteService, String sharedSession) {
- this.remoteService = remoteService;
- this.sharedSessionName = sharedSession;
- }
-
- public RemoteSession getSession() {
- return session;
- }
-
- @Override
- protected void beforeSendMessage(ClientMessage message) throws CayenneRuntimeException {
- if (session == null) {
- connect();
- }
- }
-
- @Override
- protected Object doSendMessage(ClientMessage message) throws CayenneRuntimeException {
- try {
- return remoteService.processMessage(message);
- }
- catch (CayenneRuntimeException e) {
- throw e;
- }
- catch (Throwable th) {
- throw new CayenneRuntimeException(th.getMessage(), th);
- }
- }
-
- @Override
- public EventBridge getServerEventBridge() throws CayenneRuntimeException {
- if (session == null) {
- connect();
- }
-
- return createServerEventBridge(session);
- }
-
- protected synchronized void connect() {
- if (session != null) {
- return;
- }
-
- long t0 = System.currentTimeMillis();
-
- // create server session...
- try {
- this.session = (sharedSessionName != null) ? remoteService
- .establishSharedSession(sharedSessionName) : remoteService
- .establishSession();
- }
- catch (Throwable th) {
- logger.info(th.getMessage(), th);
- throw new CayenneRuntimeException(th.getMessage(), th);
- }
-
- if (logger.isInfoEnabled()) {
- long time = System.currentTimeMillis() - t0;
- logger.info("=== Connected, session: "
- + session
- + " - took "
- + time
- + " ms.");
- }
- }
-
- /**
- * 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);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fadd1d1e/cayenne-client/src/main/java/org/apache/cayenne/rop/DefaultClientConnectionProvider.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/rop/DefaultClientConnectionProvider.java b/cayenne-client/src/main/java/org/apache/cayenne/rop/DefaultClientConnectionProvider.java
deleted file mode 100644
index 61ba2d4..0000000
--- a/cayenne-client/src/main/java/org/apache/cayenne/rop/DefaultClientConnectionProvider.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*****************************************************************
- * 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.rop;
-
-import org.apache.cayenne.ConfigurationException;
-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;
-import org.apache.cayenne.remote.ClientConnection;
-import org.apache.cayenne.rop.http.HttpROPConnector;
-
-public class DefaultClientConnectionProvider implements Provider<ClientConnection> {
-
- @Inject
- protected RuntimeProperties runtimeProperties;
-
- @Inject
- protected ROPSerializationService serializationService;
-
- @Override
- public ClientConnection get() throws DIRuntimeException {
- String sharedSession = runtimeProperties
- .get(Constants.ROP_SERVICE_SHARED_SESSION_PROPERTY);
-
- HttpROPConnector ropConnector = createHttpRopConnector();
- ProxyRemoteService remoteService = new ProxyRemoteService(serializationService, ropConnector);
-
- DefaultClientConnection clientConnection = new DefaultClientConnection(remoteService, sharedSession);
- ropConnector.setClientConnection(clientConnection);
-
- return clientConnection;
- }
-
- protected HttpROPConnector createHttpRopConnector() {
- String url = runtimeProperties.get(Constants.ROP_SERVICE_URL_PROPERTY);
- if (url == null) {
- throw new ConfigurationException(
- "No property defined for '%s', can't initialize HessianConnection",
- Constants.ROP_SERVICE_URL_PROPERTY);
- }
-
- String userName = runtimeProperties.get(Constants.ROP_SERVICE_USERNAME_PROPERTY);
- String password = runtimeProperties.get(Constants.ROP_SERVICE_PASSWORD_PROPERTY);
-
- long readTimeout = runtimeProperties.getLong(
- Constants.ROP_SERVICE_TIMEOUT_PROPERTY,
- -1L);
-
- HttpROPConnector result = new HttpROPConnector(url, userName, password);
-
- if (readTimeout > 0) {
- result.setReadTimeout(readTimeout);
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fadd1d1e/cayenne-client/src/main/java/org/apache/cayenne/rop/HttpClientConnection.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/rop/HttpClientConnection.java b/cayenne-client/src/main/java/org/apache/cayenne/rop/HttpClientConnection.java
new file mode 100644
index 0000000..06b842c
--- /dev/null
+++ b/cayenne-client/src/main/java/org/apache/cayenne/rop/HttpClientConnection.java
@@ -0,0 +1,126 @@
+/*****************************************************************
+ * 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.rop;
+
+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;
+import org.apache.cayenne.remote.RemoteSession;
+
+public class HttpClientConnection extends BaseConnection {
+
+ private RemoteService remoteService;
+ private RemoteSession session;
+
+ private String sharedSessionName;
+
+ public HttpClientConnection(RemoteService remoteService, String sharedSession) {
+ this.remoteService = remoteService;
+ this.sharedSessionName = sharedSession;
+ }
+
+ public RemoteSession getSession() {
+ return session;
+ }
+
+ @Override
+ protected void beforeSendMessage(ClientMessage message) throws CayenneRuntimeException {
+ if (session == null) {
+ connect();
+ }
+ }
+
+ @Override
+ protected Object doSendMessage(ClientMessage message) throws CayenneRuntimeException {
+ try {
+ return remoteService.processMessage(message);
+ }
+ catch (CayenneRuntimeException e) {
+ throw e;
+ }
+ catch (Throwable th) {
+ throw new CayenneRuntimeException(th.getMessage(), th);
+ }
+ }
+
+ @Override
+ public EventBridge getServerEventBridge() throws CayenneRuntimeException {
+ if (session == null) {
+ connect();
+ }
+
+ return createServerEventBridge(session);
+ }
+
+ protected synchronized void connect() {
+ if (session != null) {
+ return;
+ }
+
+ long t0 = System.currentTimeMillis();
+
+ // create server session...
+ try {
+ this.session = (sharedSessionName != null) ? remoteService
+ .establishSharedSession(sharedSessionName) : remoteService
+ .establishSession();
+ }
+ catch (Throwable th) {
+ logger.info(th.getMessage(), th);
+ throw new CayenneRuntimeException(th.getMessage(), th);
+ }
+
+ if (logger.isInfoEnabled()) {
+ long time = System.currentTimeMillis() - t0;
+ logger.info("=== Connected, session: "
+ + session
+ + " - took "
+ + time
+ + " ms.");
+ }
+ }
+
+ /**
+ * 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);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fadd1d1e/cayenne-client/src/main/java/org/apache/cayenne/rop/HttpClientConnectionProvider.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/rop/HttpClientConnectionProvider.java b/cayenne-client/src/main/java/org/apache/cayenne/rop/HttpClientConnectionProvider.java
new file mode 100644
index 0000000..ed4036c
--- /dev/null
+++ b/cayenne-client/src/main/java/org/apache/cayenne/rop/HttpClientConnectionProvider.java
@@ -0,0 +1,75 @@
+/*****************************************************************
+ * 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.rop;
+
+import org.apache.cayenne.ConfigurationException;
+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;
+import org.apache.cayenne.remote.ClientConnection;
+import org.apache.cayenne.rop.http.HttpROPConnector;
+
+public class HttpClientConnectionProvider implements Provider<ClientConnection> {
+
+ @Inject
+ protected RuntimeProperties runtimeProperties;
+
+ @Inject
+ protected ROPSerializationService serializationService;
+
+ @Override
+ public ClientConnection get() throws DIRuntimeException {
+ String sharedSession = runtimeProperties
+ .get(Constants.ROP_SERVICE_SHARED_SESSION_PROPERTY);
+
+ HttpROPConnector ropConnector = createHttpRopConnector();
+ ProxyRemoteService remoteService = new ProxyRemoteService(serializationService, ropConnector);
+
+ HttpClientConnection clientConnection = new HttpClientConnection(remoteService, sharedSession);
+ ropConnector.setClientConnection(clientConnection);
+
+ return clientConnection;
+ }
+
+ protected HttpROPConnector createHttpRopConnector() {
+ String url = runtimeProperties.get(Constants.ROP_SERVICE_URL_PROPERTY);
+ if (url == null) {
+ throw new ConfigurationException(
+ "No property defined for '%s', can't initialize HessianConnection",
+ Constants.ROP_SERVICE_URL_PROPERTY);
+ }
+
+ String userName = runtimeProperties.get(Constants.ROP_SERVICE_USERNAME_PROPERTY);
+ String password = runtimeProperties.get(Constants.ROP_SERVICE_PASSWORD_PROPERTY);
+
+ long readTimeout = runtimeProperties.getLong(
+ Constants.ROP_SERVICE_TIMEOUT_PROPERTY,
+ -1L);
+
+ HttpROPConnector result = new HttpROPConnector(url, userName, password);
+
+ if (readTimeout > 0) {
+ result.setReadTimeout(readTimeout);
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fadd1d1e/cayenne-client/src/main/java/org/apache/cayenne/rop/http/HttpROPConnector.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/main/java/org/apache/cayenne/rop/http/HttpROPConnector.java b/cayenne-client/src/main/java/org/apache/cayenne/rop/http/HttpROPConnector.java
index 198ab19..15a54ed 100644
--- a/cayenne-client/src/main/java/org/apache/cayenne/rop/http/HttpROPConnector.java
+++ b/cayenne-client/src/main/java/org/apache/cayenne/rop/http/HttpROPConnector.java
@@ -19,7 +19,7 @@
package org.apache.cayenne.rop.http;
import org.apache.cayenne.remote.RemoteSession;
-import org.apache.cayenne.rop.DefaultClientConnection;
+import org.apache.cayenne.rop.HttpClientConnection;
import org.apache.cayenne.rop.ROPConnector;
import org.apache.cayenne.rop.ROPConstants;
import org.apache.commons.logging.Log;
@@ -40,7 +40,7 @@ public class HttpROPConnector implements ROPConnector {
public static final String SESSION_COOKIE_NAME = "JSESSIONID";
- private DefaultClientConnection clientConnection;
+ private HttpClientConnection clientConnection;
private String url;
@@ -55,7 +55,7 @@ public class HttpROPConnector implements ROPConnector {
this.password = password;
}
- public void setClientConnection(DefaultClientConnection clientConnection) {
+ public void setClientConnection(HttpClientConnection clientConnection) {
this.clientConnection = clientConnection;
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fadd1d1e/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java
----------------------------------------------------------------------
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java b/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java
index 836507b..8786ff1 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java
@@ -28,7 +28,7 @@ import org.apache.cayenne.event.DefaultEventManager;
import org.apache.cayenne.remote.ClientChannel;
import org.apache.cayenne.remote.ClientConnection;
import org.apache.cayenne.remote.MockClientConnection;
-import org.apache.cayenne.rop.DefaultClientConnection;
+import org.apache.cayenne.rop.HttpClientConnection;
import org.junit.Test;
import java.util.HashMap;
@@ -52,7 +52,7 @@ public class ClientModuleTest {
ClientConnection connection = injector.getInstance(ClientConnection.class);
assertNotNull(connection);
- assertTrue(connection instanceof DefaultClientConnection);
+ assertTrue(connection instanceof HttpClientConnection);
assertSame("Connection must be a singleton", connection, injector
.getInstance(ClientConnection.class));