JBoss Remoting SVN: r4007 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-04-18 03:50:11 -0400 (Fri, 18 Apr 2008)
New Revision: 4007
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java
Log:
JBREM-953: Changed ServerThread.REUSE_AFTER_TIMEOUT to ServerThread.CONTINUE_AFTER_TIMEOUT.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java 2008-04-18 07:46:21 UTC (rev 4006)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java 2008-04-18 07:50:11 UTC (rev 4007)
@@ -99,7 +99,7 @@
{
log.info("entering " + getName());
Map config = new HashMap();
- config.put(ServerThread.REUSE_AFTER_TIMEOUT, "false");
+ config.put(ServerThread.CONTINUE_AFTER_TIMEOUT, "false");
doJavaSerializationTest(config);
log.info(getName() + " PASSES");
}
@@ -118,7 +118,7 @@
{
log.info("entering " + getName());
Map config = new HashMap();
- config.put(ServerThread.REUSE_AFTER_TIMEOUT, "true");
+ config.put(ServerThread.CONTINUE_AFTER_TIMEOUT, "true");
doJBossSerializationTest(config);
log.info(getName() + " PASSES");
}
16 years, 11 months
JBoss Remoting SVN: r4006 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-04-18 03:46:21 -0400 (Fri, 18 Apr 2008)
New Revision: 4006
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-947: Added a Timer so checking for invocation response is made on a separate thread.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2008-04-18 06:01:26 UTC (rev 4005)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2008-04-18 07:46:21 UTC (rev 4006)
@@ -32,6 +32,7 @@
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.Timer;
import java.util.TimerTask;
/**
@@ -95,6 +96,7 @@
{
boolean pingWorked = false;
Map configMap = createPingConfig(config, null);
+ int pingTimeout = Integer.parseInt((String) configMap.get(ServerInvoker.TIMEOUT));
ClientInvoker innerClientInvoker = null;
try
@@ -107,7 +109,7 @@
innerClientInvoker.connect();
}
- pingWorked = doCheckConnection(innerClientInvoker);
+ pingWorked = doCheckConnection(innerClientInvoker, pingTimeout);
}
catch (Throwable throwable)
{
@@ -127,7 +129,7 @@
return pingWorked;
}
- private static boolean doCheckConnection(ClientInvoker clientInvoker) throws Throwable
+ private static boolean doCheckConnection(ClientInvoker clientInvoker, int pingTimeout) throws Throwable
{
boolean pingWorked = false;
@@ -136,16 +138,12 @@
// Sending null client id as don't want to trigger lease on server side. This also means
// that client connection validator will NOT impact client lease, so can not depend on it
// to maintain client lease with the server.
- InvocationRequest ir =
- new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
-
- if (trace) { log.trace("pinging, sending " + ir + " over " + clientInvoker); }
-
- clientInvoker.invoke(ir);
-
- if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
-
- pingWorked = true;
+ InvocationRequest ir;
+ ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
+ ConnectionCheckThread t = new ConnectionCheckThread(clientInvoker, ir);
+ t.start();
+ Thread.sleep(pingTimeout);
+ pingWorked = t.isValid();
}
catch (Throwable t)
{
@@ -165,7 +163,18 @@
Object o = config.get(VALIDATOR_PING_TIMEOUT);
log.trace("config timeout: " + o);
if (o != null)
- localConfig.put(ServerInvoker.TIMEOUT, o);
+ {
+ try
+ {
+ Integer.parseInt((String) o);
+ localConfig.put(ServerInvoker.TIMEOUT, o);
+ }
+ catch (NumberFormatException e)
+ {
+ log.warn("Need integer for value of parameter " + VALIDATOR_PING_TIMEOUT +
+ ". Using default value " + DEFAULT_PING_TIMEOUT);
+ }
+ }
o = config.get("NumberOfCallRetries");
if (o != null)
@@ -182,7 +191,18 @@
localConfig.putAll(metadata);
Object o = metadata.get(VALIDATOR_PING_TIMEOUT);
if (o != null)
- localConfig.put(ServerInvoker.TIMEOUT, o);
+ {
+ try
+ {
+ Integer.parseInt((String) o);
+ localConfig.put(ServerInvoker.TIMEOUT, o);
+ }
+ catch (NumberFormatException e)
+ {
+ log.warn("Need integer for value of parameter " + VALIDATOR_PING_TIMEOUT +
+ ". Using default value " + DEFAULT_PING_TIMEOUT);
+ }
+ }
}
if (localConfig.get(ServerInvoker.TIMEOUT) == null)
@@ -207,10 +227,14 @@
private List listeners;
private ClientInvoker clientInvoker;
private Object lock = new Object();
+ private Object notificationLock = new Object();
private volatile boolean stopped;
private String invokerSessionId;
private boolean tieToLease = true;
private boolean stopLeaseOnFailure = true;
+ private int pingTimeout;
+ private boolean isValid;
+ private Timer timer;
// Constructors ---------------------------------------------------------------------------------
@@ -259,15 +283,26 @@
*/
public void run()
{
- synchronized(lock)
+ TimerTask tt = new WaitOnConnectionCheckTimerTask();
+
+ try
{
- if(!stopped)
+ timer.schedule(tt, 0);
+ }
+ catch (IllegalStateException e)
+ {
+ log.debug("Unable to schedule TimerTask on existing Timer", e);
+ timer = new Timer(true);
+ timer.schedule(tt, 0);
+ }
+
+ try
+ {
+ synchronized(lock)
{
- try
+ if(!stopped)
{
- if (trace) { log.trace(this + " pinging ..."); }
-
- boolean isValid = false;
+ isValid = false;
if (tieToLease && client.getLeasePeriod() > 0)
{
@@ -276,37 +311,29 @@
}
else
{
- isValid = doCheckConnection(clientInvoker);
+ if (trace) { log.trace(this + " pinging ..."); }
+ isValid = doCheckConnectionWithoutLease();
}
-
- if (!isValid)
- {
- log.debug(this + "'s connections is invalid");
-
- notifyListeners(new Exception("Could not connect to server!"));
-
- if (stopLeaseOnFailure)
- {
- log.debug(this + " detected connection failure: stopping LeasePinger");
- MicroRemoteClientInvoker invoker = (MicroRemoteClientInvoker) client.getInvoker();
- invoker.terminateLease(null, client.getDisconnectTimeout());
- log.debug(this + " shut down lease pinger");
- }
- }
}
- catch (Throwable thr)
- {
- log.debug(this + " got throwable while pinging", thr);
- notifyListeners(thr);
-
- if (stopLeaseOnFailure)
- {
- log.debug(this + " detected connection failure: stopping");
- cancel();
- }
- }
}
}
+ catch (Throwable thr)
+ {
+ log.debug(this + " got throwable while pinging", thr);
+
+ if (stopLeaseOnFailure)
+ {
+ log.debug(this + " detected connection failure: stopping");
+ cancel();
+ }
+ }
+ finally
+ {
+ synchronized (notificationLock)
+ {
+ notificationLock.notifyAll();
+ }
+ }
}
public boolean cancel()
@@ -460,7 +487,8 @@
private void start()
{
configMap = createPingConfig(client.getConfiguration(), metadata);
- log.debug(this + " timeout: " + configMap.get(ServerInvoker.TIMEOUT));
+ pingTimeout = Integer.parseInt((String) configMap.get(ServerInvoker.TIMEOUT));
+ log.debug(this + " timeout: " + pingTimeout);
log.debug(this + " ping retries: " + configMap.get("NumberOfCallRetries"));
log.debug(this + " connection retries: " + configMap.get("NumberOfRetries"));
locator = client.getInvoker().getLocator();
@@ -483,7 +511,7 @@
TimerUtil.schedule(this, pingPeriod);
stopped = false;
-
+ timer = new Timer(true);
log.debug(this + " started");
}
@@ -518,7 +546,35 @@
return pingWorked;
}
+
+ private boolean doCheckConnectionWithoutLease() throws Throwable
+ {
+ boolean pingWorked = false;
+ try
+ {
+ // Sending null client id as don't want to trigger lease on server side. This also means
+ // that client connection validator will NOT impact client lease, so can not depend on it
+ // to maintain client lease with the server.
+ InvocationRequest ir =
+ new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
+
+ if (trace) { log.trace("pinging, sending " + ir + " over " + clientInvoker); }
+
+ clientInvoker.invoke(ir);
+
+ if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
+
+ pingWorked = true;
+ }
+ catch (Throwable t)
+ {
+ log.debug("ConnectionValidator failed to ping via " + clientInvoker, t);
+ }
+
+ return pingWorked;
+ }
+
private boolean doStop()
{
synchronized(lock)
@@ -569,4 +625,80 @@
// Inner classes --------------------------------------------------------------------------------
+ private class WaitOnConnectionCheckTimerTask extends TimerTask
+ {
+ public void run()
+ {
+ long start = System.currentTimeMillis();
+ synchronized (notificationLock)
+ {
+ while (true)
+ {
+ int elapsed = (int) (System.currentTimeMillis() - start);
+ int wait = pingTimeout - elapsed;
+ if (wait <= 0) break;
+
+ try
+ {
+ notificationLock.wait(wait);
+ break;
+ }
+ catch (InterruptedException e)
+ {
+ continue;
+ }
+ }
+ }
+
+ if (!isValid)
+ {
+ log.debug(ConnectionValidator.this + "'s connections is invalid");
+
+ notifyListeners(new Exception("Could not connect to server!"));
+
+ if (stopLeaseOnFailure)
+ {
+ log.debug(this + " detected connection failure: stopping LeasePinger");
+ MicroRemoteClientInvoker invoker = (MicroRemoteClientInvoker) client.getInvoker();
+ invoker.terminateLease(null, client.getDisconnectTimeout());
+ log.debug(this + " shut down lease pinger");
+ cancel();
+ }
+ }
+ }
+ }
+
+ private static class ConnectionCheckThread extends Thread
+ {
+ private InvocationRequest ir;
+ private ClientInvoker clientInvoker;
+ private boolean isValid;
+
+ public ConnectionCheckThread(ClientInvoker clientInvoker, InvocationRequest ir)
+ {
+ this.clientInvoker = clientInvoker;
+ this.ir = ir;
+ setDaemon(true);
+ }
+
+ public void run()
+ {
+ try
+ {
+ if (trace) { log.trace("pinging, sending " + ir + " over " + clientInvoker); }
+ clientInvoker.invoke(ir);
+ isValid = true;
+ if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
+ }
+ catch (Throwable t)
+ {
+ log.debug("ConnectionValidator failed to ping via " + clientInvoker, t);
+ }
+ }
+
+ public boolean isValid()
+ {
+ return isValid;
+ }
+ }
}
\ No newline at end of file
16 years, 11 months
JBoss Remoting SVN: r4005 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-04-18 02:01:26 -0400 (Fri, 18 Apr 2008)
New Revision: 4005
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/InvocationFailureException.java
Log:
JBREM-964: Is now derived from MarshalException.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/InvocationFailureException.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/InvocationFailureException.java 2008-04-18 03:43:57 UTC (rev 4004)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/InvocationFailureException.java 2008-04-18 06:01:26 UTC (rev 4005)
@@ -22,8 +22,8 @@
*/
package org.jboss.remoting;
-import java.io.IOException;
import java.lang.Exception;
+import java.rmi.MarshalException;
/**
* Indicates a client invoker was unable to perform an invocation.
@@ -34,20 +34,19 @@
* Copyright Dec 29, 2007
* </p>
*/
-public class InvocationFailureException extends IOException
+public class InvocationFailureException extends MarshalException
{
/** The serialVersionUID */
private static final long serialVersionUID = -5852787672018746296L;
public InvocationFailureException()
{
- super();
+ super("");
}
public InvocationFailureException(Exception e)
{
- super();
- initCause(e);
+ super("", e);
}
public InvocationFailureException(String message)
@@ -57,8 +56,7 @@
public InvocationFailureException(String message, Exception e)
{
- super(message);
- initCause(e);
+ super(message, e);
}
}
16 years, 11 months
JBoss Remoting SVN: r4004 - remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-04-17 23:43:57 -0400 (Thu, 17 Apr 2008)
New Revision: 4004
Modified:
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
Prevent a leak
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
--- remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-04-18 03:43:41 UTC (rev 4003)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-04-18 03:43:57 UTC (rev 4004)
@@ -64,7 +64,7 @@
if (endpoint instanceof CoreEndpoint) {
final CoreEndpoint coreEndpoint = (CoreEndpoint) endpoint;
final ConcurrentMap<Object, Object> attributes = coreEndpoint.getAttributes();
- final JrppProtocolSupport jrppProtocolSupport = (JrppProtocolSupport) attributes.get(JRPP_SUPPORT_KEY);
+ final JrppProtocolSupport jrppProtocolSupport = (JrppProtocolSupport) attributes.remove(JRPP_SUPPORT_KEY);
coreEndpoint.stop();
coreEndpoint.destroy();
if (jrppProtocolSupport != null) {
16 years, 11 months
JBoss Remoting SVN: r4003 - remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-04-17 23:43:41 -0400 (Thu, 17 Apr 2008)
New Revision: 4003
Modified:
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieValidator.java
Log:
One last validation rule
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieValidator.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieValidator.java 2008-04-18 02:17:50 UTC (rev 4002)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieValidator.java 2008-04-18 03:43:41 UTC (rev 4003)
@@ -15,6 +15,9 @@
private static final String DOMAIN_PATTERN_STRING = "^(?:(?:[a-zA-Z0-9][a-zA-Z0-9]+)(?:-(?:[a-zA-Z0-9][a-zA-Z0-9]+))*(?:\\.(?:(?:[a-zA-Z0-9][a-zA-Z0-9]+)(?:-(?:[a-zA-Z0-9][a-zA-Z0-9]+))*)+$";
private static final Pattern DOMAIN_PATTERN = Pattern.compile(DOMAIN_PATTERN_STRING);
+ private static final String COOKIE_PATTERN_STRING = "^([^=;,\\p{Space}]*)$";
+ private static final Pattern COOKIE_PATTERN = Pattern.compile(COOKIE_PATTERN_STRING);
+
private static final Set<String> TLD_SET;
private static final Logger log = Logger.getLogger(SimpleCookieValidator.class);
@@ -73,7 +76,15 @@
logReject(cookie, requestDomain, "cookie path is invalid");
return false;
}
- log.trace("Accepting cookie \"%s\" from request domain \"%s\"", cookie.getName(), requestDomain);
+ final String name = cookie.getName();
+ if (! COOKIE_PATTERN.matcher(name).matches()) {
+ logReject(cookie, requestDomain, "cookie name is invalid");
+ }
+ final String value = cookie.getValue();
+ if (! COOKIE_PATTERN.matcher(value).matches()) {
+ logReject(cookie, requestDomain, "cookie value is invalid");
+ }
+ log.trace("Accepting cookie \"%s\" from request domain \"%s\"", name, requestDomain);
return true;
}
}
16 years, 11 months
JBoss Remoting SVN: r4002 - remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-04-17 22:17:50 -0400 (Thu, 17 Apr 2008)
New Revision: 4002
Removed:
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieDomain.java
Modified:
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/Cookie.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieClientSession.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieMatcher.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieParser.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieValidator.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieMatcher.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieParser.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieValidator.java
Log:
Redo (and simplify) cookies
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/Cookie.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/Cookie.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/Cookie.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -12,12 +12,12 @@
private final String value;
private final String name;
private final String path;
- private final CookieDomain domain;
+ private final String domain;
private final long expires;
private final boolean secure;
private final Key key;
- public Cookie(final String name, final String value, final String path, final CookieDomain domain, final long expires, final boolean secure) {
+ public Cookie(final String name, final String value, final String path, final String domain, final long expires, final boolean secure) {
this.expires = expires;
if (name == null) {
throw new NullPointerException("name is null");
@@ -34,7 +34,7 @@
this.name = name;
this.value = value;
this.path = path;
- this.domain = domain;
+ this.domain = domain.toLowerCase();
this.secure = secure;
key = new Key(name, path);
}
@@ -51,7 +51,7 @@
return path;
}
- public CookieDomain getDomain() {
+ public String getDomain() {
return domain;
}
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieClientSession.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieClientSession.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieClientSession.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -41,10 +41,9 @@
* @return the cookie header value
*/
public String getCookieHeader(String domain, String path, boolean secureRequest) {
- final CookieDomain cookieDomain = new CookieDomain(domain);
final SortedMap<Cookie.Key, Cookie> sortedValidatedCookies = new TreeMap<Cookie.Key, Cookie>();
for (final Cookie cookie : cookieMap.values()) {
- if (cookieMatcher.matches(cookie, cookieDomain, path, secureRequest)) {
+ if (cookieMatcher.matches(cookie, domain, path, secureRequest)) {
sortedValidatedCookies.put(cookie.getKey(), cookie);
}
}
@@ -66,15 +65,12 @@
* @param path the request path
*/
public void handleSetCookieHeader(String headerValue, String domain, String path) {
- final CookieDomain requestDomain = new CookieDomain(domain);
- final Cookie[] cookies = cookieParser.parseSetCookie(headerValue, requestDomain, path);
- for (Cookie cookie : cookies) {
- if (! cookieValidator.isValid(cookie, requestDomain)) {
- log.trace("Ignoring invalid cookie %s", cookie);
- } else {
- log.trace("Adding cookie '%s' from domain '%s'", cookie, requestDomain);
- cookieMap.put(cookie.getKey(), cookie);
- }
+ final Cookie cookie = cookieParser.parseSetCookie(headerValue, domain, path);
+ if (! cookieValidator.isValid(cookie, domain)) {
+ log.trace("Ignoring invalid cookie %s", cookie);
+ } else {
+ log.trace("Adding cookie '%s' from domain '%s'", cookie, domain);
+ cookieMap.put(cookie.getKey(), cookie);
}
}
}
Deleted: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieDomain.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieDomain.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieDomain.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -1,87 +0,0 @@
-package org.jboss.cx.remoting.http.cookie;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import org.jboss.cx.remoting.util.CollectionUtil;
-import static org.jboss.cx.remoting.util.CollectionUtil.split;
-import static org.jboss.cx.remoting.util.CollectionUtil.toArrayReversed;
-
-/**
- *
- */
-public final class CookieDomain implements Serializable {
-
- public static final CookieDomain LOCAL = new CookieDomain(".local");
-
- private static final long serialVersionUID = 1L;
-
- private final String[] parts;
- private final boolean hostDomainName;
-
- private CookieDomain(String[] parts, boolean hostDomainName) {
- this.parts = parts;
- this.hostDomainName = hostDomainName;
- }
-
- public CookieDomain(String domain) {
- if (domain == null) {
- throw new NullPointerException("domain is null");
- }
- if (domain.length() == 0) {
- throw new IllegalArgumentException("domain is empty");
- }
- hostDomainName = domain.charAt(0) == '.';
- final String baseDomain = hostDomainName ? domain.substring(1).toLowerCase() : domain.toLowerCase();
- parts = toArrayReversed(split(".", baseDomain).iterator(), String.class);
- }
-
- public boolean equals(final CookieDomain other) {
- return other != null && hostDomainName == other.hostDomainName && Arrays.equals(parts, other.parts);
- }
-
- public boolean equals(final Object other) {
- return other instanceof CookieDomain && equals((CookieDomain)other);
- }
-
- public int hashCode() {
- return Arrays.hashCode(parts) + (hostDomainName ? 1 : 0);
- }
-
- public String toString() {
- final StringBuilder builder = new StringBuilder(40);
- builder.append("Domain: ");
- for (String x : parts) {
- builder.append(x);
- builder.append('/');
- }
- builder.setLength(builder.length() - 1);
- return builder.toString();
- }
-
- public boolean matches(final CookieDomain other) {
- // todo this doesn't quite match rfc 2965
- return other.hostDomainName ? CollectionUtil.arrayStartsWith(parts, other.parts) : Arrays.equals(other.parts, parts);
- }
-
- public int getPartCount() {
- return parts.length;
- }
-
- public String getPart(int index) {
- return parts[index];
- }
-
- public boolean hasParent() {
- return parts.length > 1;
- }
-
- public boolean isHostDomainName() {
- return hostDomainName;
- }
-
- public CookieDomain getParent() {
- final String[] parentParts = new String[parts.length - 1];
- System.arraycopy(parts, 0, parentParts, 0, parentParts.length);
- return new CookieDomain(parentParts, false);
- }
-}
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieMatcher.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieMatcher.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieMatcher.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -14,5 +14,5 @@
* @param secure whether the request is on a secure channel
* @return {@code true} if the cookie should be sent
*/
- boolean matches(Cookie cookie, CookieDomain requestDomain, String path, boolean secure);
+ boolean matches(Cookie cookie, String requestDomain, String path, boolean secure);
}
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieParser.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieParser.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieParser.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -4,5 +4,5 @@
*
*/
public interface CookieParser {
- Cookie[] parseSetCookie(String setCookie, CookieDomain defaultDomain, String defaultPath);
+ Cookie parseSetCookie(String setCookie, String defaultDomain, String defaultPath);
}
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieValidator.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieValidator.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/CookieValidator.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -9,8 +9,8 @@
* Determine whether a cookie from a server is valid.
*
* @param cookie the cookie from the server
- * @param fromDomain the actual domain that the request was sent to
+ * @param requestDomain the domain that the request was sent to
* @return {@code true} if the cookie is valid
*/
- boolean isValid(Cookie cookie, CookieDomain fromDomain);
+ boolean isValid(Cookie cookie, String requestDomain);
}
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieMatcher.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieMatcher.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieMatcher.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -5,12 +5,12 @@
*/
public final class SimpleCookieMatcher implements CookieMatcher {
- public boolean matches(final Cookie cookie, final CookieDomain requestDomain, final String path, final boolean secure) {
+ public boolean matches(final Cookie cookie, final String requestDomain, final String path, final boolean secure) {
final boolean cookieSecure = cookie.isSecure();
if (cookieSecure && ! secure) {
return false;
}
- final CookieDomain cookieDomain = cookie.getDomain();
+ final String cookieDomain = cookie.getDomain();
final String cookiePath = cookie.getPath();
return requestDomain.matches(cookieDomain) && path.startsWith(cookiePath) && !cookie.isExpired();
}
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieParser.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieParser.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieParser.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -2,9 +2,9 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.jboss.cx.remoting.log.Logger;
-import org.jboss.cx.remoting.util.CollectionUtil;
/**
*
@@ -26,7 +26,10 @@
}
}
- public Cookie[] parseSetCookie(final String setCookie, final CookieDomain defaultDomain, final String defaultPath) {
+ private static final String PAIR_PATTERN_STRING = "(\\s*+[^=;]*?)(?:\\s+=\\s*+([^;]*?)\\s+)(?:;|$)";
+ private static final Pattern PAIR_PATTERN = Pattern.compile(PAIR_PATTERN_STRING);
+
+ public Cookie parseSetCookie(final String setCookie, final String defaultDomain, final String defaultPath) {
if (setCookie == null) {
throw new NullPointerException("setCookie is null");
}
@@ -36,48 +39,46 @@
if (defaultPath == null) {
throw new NullPointerException("defaultPath is null");
}
+ final Matcher matcher = PAIR_PATTERN.matcher(setCookie);
+ if (! matcher.find()) {
+ return null; // no cookie!
+ }
+ final String name = matcher.group(1);
+ final String value = matcher.group(2);
+ if (name == null || value == null) {
+ return null; // no cookie!
+ }
boolean secure = false;
long expires = 0L;
- CookieDomain domain = defaultDomain;
String path = defaultPath;
- List<Pair> pairs = CollectionUtil.arrayList();
- for (final String s : CollectionUtil.split(";", setCookie)) {
- final String assignment = s.trim();
- final int equalsPos = assignment.indexOf('=');
- if (equalsPos == -1) {
- if (assignment.toLowerCase().equals("secure")) {
- secure = true;
- continue;
+ String domain = defaultDomain;
+ while (matcher.find()) {
+ final String attrName = matcher.group(1);
+ final String attrValue = matcher.group(2);
+ if ("secure".equalsIgnoreCase(attrName) && attrValue == null) {
+ secure = true;
+ } else if ("expires".equalsIgnoreCase(attrName) && attrValue != null) {
+ final int gmti = value.lastIndexOf(" GMT");
+ final String dateValue;
+ if (gmti != -1) {
+ dateValue = attrValue.substring(0, gmti);
+ } else {
+ dateValue = attrValue;
}
+ final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+ try {
+ expires = dateFormat.parse(dateValue).getTime();
+ } catch (ParseException e) {
+ log.trace("Invalid cookie expiration date '%s'", value);
+ }
+ } else if ("domain".equalsIgnoreCase(attrName) && attrValue != null) {
+ domain = attrValue;
+ } else if ("path".equalsIgnoreCase(attrName) && attrValue != null) {
+ path = attrValue;
} else {
- String name = assignment.substring(0, equalsPos).trim();
- String lowerName = name.toLowerCase();
- String value = assignment.substring(equalsPos + 1).trim();
- if (lowerName.equals("expires")) {
- final int gmti = value.lastIndexOf(" GMT");
- if (gmti != -1) {
- value = value.substring(0, gmti);
- }
- final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
- try {
- expires = dateFormat.parse(value).getTime();
- } catch (ParseException e) {
- log.trace("Invalid cookie expiration date '%s'", value);
- }
- } else if (lowerName.equals("domain")) {
- domain = new CookieDomain(value);
- } else if (lowerName.equals("path")) {
- path = value;
- } else {
- pairs.add(new Pair(name, value));
- }
+ log.trace("Unknown cookie attribute-value pair: \"%s\"=\"%s\"", attrName, attrValue);
}
}
- Cookie[] cookies = new Cookie[pairs.size()];
- int i = 0;
- for (Pair pair : pairs) {
- cookies[i++] = new Cookie(pair.name, pair.value, path, domain, expires, secure);
- }
- return cookies;
+ return new Cookie(name, value, path, domain, expires, secure);
}
}
Modified: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieValidator.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieValidator.java 2008-04-17 03:03:00 UTC (rev 4001)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/cookie/SimpleCookieValidator.java 2008-04-18 02:17:50 UTC (rev 4002)
@@ -3,6 +3,8 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import java.util.regex.Pattern;
+import org.jboss.cx.remoting.log.Logger;
/**
* Simple cookie validator. Validates a cookie coming down from a server. See
@@ -10,8 +12,13 @@
* for more info.
*/
public final class SimpleCookieValidator implements CookieValidator {
+ private static final String DOMAIN_PATTERN_STRING = "^(?:(?:[a-zA-Z0-9][a-zA-Z0-9]+)(?:-(?:[a-zA-Z0-9][a-zA-Z0-9]+))*(?:\\.(?:(?:[a-zA-Z0-9][a-zA-Z0-9]+)(?:-(?:[a-zA-Z0-9][a-zA-Z0-9]+))*)+$";
+ private static final Pattern DOMAIN_PATTERN = Pattern.compile(DOMAIN_PATTERN_STRING);
+
private static final Set<String> TLD_SET;
+ private static final Logger log = Logger.getLogger(SimpleCookieValidator.class);
+
static {
final HashSet<String> tldSet = new HashSet<String>();
tldSet.add("com");
@@ -24,29 +31,49 @@
TLD_SET = Collections.unmodifiableSet(tldSet);
}
- public boolean isValid(final Cookie cookie, final CookieDomain requestDomain) {
- final CookieDomain cookieDomain = cookie.getDomain();
- for (int i = 0; i < cookieDomain.getPartCount(); i++) {
- if (cookieDomain.getPart(i).length() == 0) {
- return false;
- }
+ private static void logReject(Cookie cookie, String requestDomain, String reason) {
+ log.trace("Rejecting cookie \"%s\" from request domain \"%s\": %s", cookie.getName(), requestDomain, reason);
+ }
+
+ public boolean isValid(final Cookie cookie, final String requestDomain) {
+
+ final String cookieDomain = cookie.getDomain();
+ final String matchDomain;
+ if (cookieDomain.length() == 0) {
+ logReject(cookie, requestDomain, "cookie domain length is zero");
+ return false;
}
- final int numParts = cookieDomain.getPartCount() + (cookieDomain.isHostDomainName() ? 1 : 0);
- final String tld = numParts == 0 ? null : cookieDomain.getPart(0);
- final int minSegments = TLD_SET.contains(tld) ? 3 : 4;
- if (numParts < minSegments) {
- // not valid: domain name is too short
+ if (cookieDomain.charAt(0) == '.') {
+ matchDomain = cookieDomain.substring(1);
+ } else {
+ matchDomain = cookieDomain;
+ }
+ if (! DOMAIN_PATTERN.matcher(matchDomain).matches()) {
+ logReject(cookie, requestDomain, "cookie has an invalid domain");
return false;
}
+ final String effectiveDomain;
+ if (matchDomain.indexOf('.') == -1) {
+ effectiveDomain = matchDomain + ".local";
+ } else {
+ effectiveDomain = matchDomain;
+ }
+ final String tld = effectiveDomain.substring(effectiveDomain.lastIndexOf('.') + 1);
+ final int minDots = TLD_SET.contains(tld) ? 1 : 2;
+ int dotCount = 0;
+ for (int p = effectiveDomain.indexOf('.', 0); p != -1; p = effectiveDomain.indexOf('.', p + 1)) {
+ dotCount ++;
+ }
+ if (dotCount < minDots) {
+ logReject(cookie, requestDomain, "cookie domain name is too short (see http://wp.netscape.com/newsref/std/cookie_spec.html)");
+ return false;
+ }
final String path = cookie.getPath();
if (path.length() == 0 || path.charAt(0) != '/') {
- // not valid: bad or missing path
+ logReject(cookie, requestDomain, "cookie path is invalid");
return false;
}
- if (! requestDomain.matches(cookieDomain)) {
- // wrong domain
- return false;
- }
+ log.trace("Accepting cookie \"%s\" from request domain \"%s\"", cookie.getName(), requestDomain);
return true;
}
}
16 years, 11 months
JBoss Remoting SVN: r4001 - remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-04-16 23:03:00 -0400 (Wed, 16 Apr 2008)
New Revision: 4001
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/ObjectResolver.java
Log:
Minor changes to marshallers - but this is the new api which is not yet implemented - so: nothing to see here, move along
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java 2008-04-17 00:49:34 UTC (rev 4000)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/Marshaller.java 2008-04-17 03:03:00 UTC (rev 4001)
@@ -1,6 +1,7 @@
package org.jboss.cx.remoting.spi.marshal;
import java.io.IOException;
+import java.io.Serializable;
import org.jboss.cx.remoting.spi.DataMessageInput;
import org.jboss.cx.remoting.spi.DataMessageOutput;
import org.jboss.cx.remoting.spi.ObjectMessageInput;
@@ -9,15 +10,11 @@
/**
*
*/
-public interface Marshaller {
+public interface Marshaller extends Serializable {
ObjectMessageOutput getMessageOutput(DataMessageOutput dataMessageOutput) throws IOException;
ObjectMessageInput getMessageInput(DataMessageInput dataMessageInput) throws IOException;
- Marshaller createChild() throws IOException;
-
- Marshaller createChild(ClassLoader classLoader) throws IOException;
-
void addFirstObjectResolver(ObjectResolver resolver);
void addLastObjectResolver(ObjectResolver resolver);
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/ObjectResolver.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/ObjectResolver.java 2008-04-17 00:49:34 UTC (rev 4000)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/marshal/ObjectResolver.java 2008-04-17 03:03:00 UTC (rev 4001)
@@ -1,11 +1,12 @@
package org.jboss.cx.remoting.spi.marshal;
import java.io.IOException;
+import java.io.Serializable;
/**
*
*/
-public interface ObjectResolver {
+public interface ObjectResolver extends Serializable {
Object readResolve(Object original) throws IOException;
Object writeReplace(Object original) throws IOException;
16 years, 11 months
JBoss Remoting SVN: r4000 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-04-16 20:49:34 -0400 (Wed, 16 Apr 2008)
New Revision: 4000
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java
Log:
JBREM-953: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java 2008-04-17 00:49:34 UTC (rev 4000)
@@ -0,0 +1,305 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.timeout;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.socket.LRUPool;
+import org.jboss.remoting.transport.socket.ServerThread;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+public class ServerThreadReuseAfterTimeoutTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ServerThreadReuseAfterTimeoutTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testJavaSerializationDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+ Map config = new HashMap();
+ doJavaSerializationTest(config);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testJavaSerializationConfigured() throws Throwable
+ {
+ log.info("entering " + getName());
+ Map config = new HashMap();
+ config.put(ServerThread.REUSE_AFTER_TIMEOUT, "false");
+ doJavaSerializationTest(config);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testJBossSerializationDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+ Map config = new HashMap();
+ doJBossSerializationTest(config);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testJBossSerializationConfigured() throws Throwable
+ {
+ log.info("entering " + getName());
+ Map config = new HashMap();
+ config.put(ServerThread.REUSE_AFTER_TIMEOUT, "true");
+ doJBossSerializationTest(config);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void doJavaSerializationTest(Map clientConfig) throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer("java");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Get ServerThread.
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool clientpool = (LRUPool) field.get(invoker);
+ assertEquals(1, clientpool.size());
+ Set s = clientpool.getContents();
+ ServerThread serverThread1 = (ServerThread) s.iterator().next();
+
+ // Get threadpool.
+ field = SocketServerInvoker.class.getDeclaredField("threadpool");
+ field.setAccessible(true);
+ LinkedList threadpool = (LinkedList) field.get(invoker);
+ assertEquals(0, threadpool.size());
+
+ // Wait for ServerThread to time out.
+ Thread.sleep(6000);
+ for (int i = 0; i < 5; i++)
+ {
+ Thread.sleep(2000);
+ if (clientpool.size() == 0) break;
+ }
+
+ if (clientpool.size() > 0)
+ {
+ fail("expect clientpool.size() == 0");
+ }
+
+ // Verify original ServerThread was returned to threadpool.
+ assertEquals(1, threadpool.size());
+ assertEquals(serverThread1, threadpool.iterator().next());
+
+ // Make another invocation and verify ServerThread was reused.
+ client.invoke("xyz");
+ assertEquals(1, clientpool.size());
+ s = clientpool.getContents();
+ ServerThread serverThread2 = (ServerThread) s.iterator().next();
+ assertEquals(serverThread1, serverThread2);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void doJBossSerializationTest(Map clientConfig) throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer("jboss");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Get clientpool and ServerThread.
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool clientpool = (LRUPool) field.get(invoker);
+ assertEquals(1, clientpool.size());
+ Set clientpoolContents = clientpool.getContents();
+ ServerThread serverThread1 = (ServerThread) clientpoolContents.iterator().next();
+
+ // Get threadpool.
+ field = SocketServerInvoker.class.getDeclaredField("threadpool");
+ field.setAccessible(true);
+ LinkedList threadpool = (LinkedList) field.get(invoker);
+ assertEquals(0, threadpool.size());
+
+ // Wait for ServerThread to time out.
+ Thread.sleep(8000);
+
+ // Verify original ServerThread remains in clientpool.
+ assertEquals(0, threadpool.size());
+ assertEquals(1, clientpool.size());
+ clientpoolContents = clientpool.getContents();
+ assertEquals(serverThread1, clientpoolContents.iterator().next());
+
+ // Make another invocation and verify ServerThread was reused.
+ client.invoke("xyz");
+ assertEquals(1, clientpool.size());
+ clientpoolContents = clientpool.getContents();
+ ServerThread serverThread2 = (ServerThread) clientpoolContents.iterator().next();
+ assertEquals(serverThread1, serverThread2);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(String serializationType) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?timeout=4000";
+ locatorURI += "&serializationtype=" + serializationType;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+}
\ No newline at end of file
16 years, 11 months
JBoss Remoting SVN: r3999 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-04-16 20:48:55 -0400 (Wed, 16 Apr 2008)
New Revision: 3999
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java
Log:
JBREM-953: (1) Added CONTINUE_AFTER_TIMEOUT flag and related processing; (2) uses SecurityUtility to get classloader.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2008-04-16 18:08:27 UTC (rev 3998)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2008-04-17 00:48:55 UTC (rev 3999)
@@ -32,12 +32,14 @@
import org.jboss.remoting.Version;
import org.jboss.remoting.Client;
import org.jboss.remoting.serialization.ClassLoaderUtility;
+import org.jboss.remoting.util.SecurityUtility;
import org.jboss.remoting.invocation.OnewayInvocation;
import org.jboss.remoting.marshal.MarshalFactory;
import org.jboss.remoting.marshal.Marshaller;
import org.jboss.remoting.marshal.UnMarshaller;
import org.jboss.remoting.marshal.VersionedMarshaller;
import org.jboss.remoting.marshal.VersionedUnMarshaller;
+import org.jboss.serial.io.JBossObjectInputStream;
import java.io.EOFException;
import java.io.IOException;
@@ -82,6 +84,10 @@
public static final String EVICTABILITY_TIMEOUT = "evictabilityTimeout";
public static final int EVICTABILITY_TIMEOUT_DEFAULT = 10000;
+ /** Key used to determine if thread should return to threadpool after
+ * SocketTimeoutException */
+ public static final String CONTINUE_AFTER_TIMEOUT = "continueAfterTimeout";
+
final static private Logger log = Logger.getLogger(ServerThread.class);
// Static ---------------------------------------------------------------------------------------
@@ -137,6 +143,8 @@
// Period during which ServerThread is not evictable on first
// invocation even when in evictable state. */
private int evictabilityTimeout = EVICTABILITY_TIMEOUT_DEFAULT;
+
+ private boolean reuseAfterTimeout;
// Constructors ---------------------------------------------------------------------------------
@@ -456,6 +464,32 @@
socketWrapper =
createServerSocketWrapper(socket, timeout, invoker.getLocator().getParameters());
+ boolean valueSet = false;
+ Map configMap = invoker.getConfiguration();
+ Object o = configMap.get(CONTINUE_AFTER_TIMEOUT);
+ if (o != null)
+ {
+ try
+ {
+ reuseAfterTimeout = Boolean.valueOf((String)o).booleanValue();
+ valueSet = true;
+ log.debug(this + " setting reuseAfterTimeout to " + reuseAfterTimeout);
+ }
+ catch (Exception e)
+ {
+ log.warn(this + " could not convert " + CONTINUE_AFTER_TIMEOUT +
+ " value of " + o + " to a boolean value");
+ }
+ }
+
+ if (!valueSet)
+ {
+ if (socketWrapper.getInputStream() instanceof JBossObjectInputStream)
+ {
+ reuseAfterTimeout = true;
+ }
+ }
+
// Always do first one without an ACK because its not needed
if(trace) { log.trace("processing first invocation without acknowledging"); }
processInvocation(socketWrapper);
@@ -509,6 +543,9 @@
log.trace(this + " timed out", ste);
}
}
+
+ if (!reuseAfterTimeout)
+ running = false;
}
catch (InterruptedIOException e)
{
@@ -540,7 +577,7 @@
}
catch (SocketException sex)
{
- if (!shutdown && true)
+ if (!shutdown && trace)
{
if (trace) log.trace(this + " SocketException received. This is likely due to client disconnecting and resetting connection.", sex);
}
@@ -903,14 +940,7 @@
{
InvokerLocator locator = invoker.getLocator();
- ClassLoader classLoader = (ClassLoader) AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return ServerThread.class.getClassLoader();
- }
- });
-
+ ClassLoader classLoader = SecurityUtility.getClassLoader(ServerThread.class);
String dataType = invoker.getDataType();
String serializationType = invoker.getSerializationType();
16 years, 11 months
JBoss Remoting SVN: r3998 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting/spi/wrapper and 4 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-04-16 14:08:27 -0400 (Wed, 16 Apr 2008)
New Revision: 3998
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppProtocolSupport.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
"bean"-ify Endpoint - now an endpoint must be maintained by a container or by the Remoting utility class
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -11,7 +11,7 @@
/**
* A potential participant in a JBoss Remoting communications relationship.
*/
-public interface Endpoint extends Closeable<Endpoint> {
+public interface Endpoint {
/**
* Get the endpoint attribute map. This is a storage area for any data associated with this endpoint, including
* (but not limited to) connection and protocol information, and application information.
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -2,7 +2,6 @@
import java.net.URI;
import java.util.concurrent.ConcurrentMap;
-import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.Endpoint;
@@ -61,20 +60,4 @@
public void removeSessionListener(final SessionListener sessionListener) {
delegate.removeSessionListener(sessionListener);
}
-
- public void close() throws RemotingException {
- delegate.close();
- }
-
- public void closeImmediate() throws RemotingException {
- delegate.closeImmediate();
- }
-
- public void addCloseHandler(final CloseHandler<Endpoint> closeHandler) {
- delegate.addCloseHandler(new CloseHandler<Endpoint>() {
- public void handleClose(final Endpoint closed) {
- closeHandler.handleClose(EndpointWrapper.this);
- }
- });
- }
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -2,15 +2,12 @@
import java.io.IOException;
import java.net.URI;
-import java.util.Iterator;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.Endpoint;
@@ -38,19 +35,10 @@
/**
*
*/
-public final class CoreEndpoint {
+public class CoreEndpoint implements Endpoint {
- private final String name;
- private final RequestListener<?, ?> rootListener;
- private final Endpoint userEndpoint = new UserEndpoint();
- private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.INITIAL);
- private final Set<SessionListener> sessionListeners = CollectionUtil.synchronizedSet(new LinkedHashSet<SessionListener>());
-
- private OrderedExecutorFactory orderedExecutorFactory;
- private Executor executor;
- private ExecutorService executorService;
-
static {
+ // Print Remoting "greeting" message
Logger.getLogger("org.jboss.cx.remoting").info("JBoss Remoting version %s", Version.VERSION);
}
@@ -60,51 +48,72 @@
DOWN;
public boolean isReachable(final State dest) {
- switch (this) {
- case INITIAL:
- return dest != INITIAL;
- case UP:
- return dest == DOWN;
- default:
- return false;
- }
+ return compareTo(dest) < 0;
}
}
- public CoreEndpoint(final String name, final RequestListener<?, ?> rootListener) {
- this.name = name;
- this.rootListener = rootListener;
- }
+ private String name;
+ private RequestListener<?, ?> rootListener;
+ private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.INITIAL);
+ private final Set<SessionListener> sessionListeners = CollectionUtil.synchronizedSet(new LinkedHashSet<SessionListener>());
+
+ private OrderedExecutorFactory orderedExecutorFactory;
+ private ExecutorService executorService;
+
private final ConcurrentMap<Object, Object> endpointMap = CollectionUtil.concurrentMap();
private final ConcurrentMap<String, CoreProtocolRegistration> protocolMap = CollectionUtil.concurrentMap();
private final Set<CoreSession> sessions = CollectionUtil.synchronizedSet(CollectionUtil.<CoreSession>hashSet());
- // accesses protected by {@code shutdownListeners} - always lock AFTER {@code state}
- private final List<CloseHandler<Endpoint>> closeHandlers = CollectionUtil.synchronizedArrayList();
+ public CoreEndpoint() {
+ }
+
+ // Dependencies
+
+ private Executor executor;
+
public Executor getExecutor() {
return executor;
}
+ public Executor getOrderedExecutor() {
+ return orderedExecutorFactory.getOrderedExecutor();
+ }
+
public void setExecutor(final Executor executor) {
this.executor = executor;
orderedExecutorFactory = new OrderedExecutorFactory(executor);
}
- public Endpoint getUserEndpoint() {
- return userEndpoint;
+ // Configuration
+
+ public void setName(final String name) {
+ this.name = name;
}
- void removeSession(CoreSession coreSession) {
- synchronized (sessions) {
- if (!sessions.remove(coreSession)) {
- return;
- }
- sessions.notifyAll();
+ public String getName() {
+ return name;
+ }
+
+ public void setRootListener(final RequestListener<?, ?> rootListener) {
+ this.rootListener = rootListener;
+ }
+
+ public RequestListener<?, ?> getRootListener() {
+ return rootListener;
+ }
+
+ // Lifecycle
+
+ public void create() {
+ // todo security check
+ if (rootListener == null) {
+ throw new NullPointerException("rootListener is null");
}
}
public void start() {
+ // todo security check
if (executor == null) {
executorService = Executors.newCachedThreadPool();
setExecutor(executorService);
@@ -113,6 +122,7 @@
}
public void stop() {
+ // todo security check
if (executorService != null) {
executorService.shutdown();
executorService = null;
@@ -120,10 +130,123 @@
// todo
}
- Executor getOrderedExecutor() {
- return orderedExecutorFactory.getOrderedExecutor();
+ public void destroy() {
+ rootListener = null;
+ executor = null;
}
+
+ // Endpoint implementation
+
+ public ConcurrentMap<Object, Object> getAttributes() {
+ return endpointMap;
+ }
+
+ public Session openSession(final URI uri, final AttributeMap attributeMap) throws RemotingException {
+ if (uri == null) {
+ throw new NullPointerException("uri is null");
+ }
+ if (attributeMap == null) {
+ throw new NullPointerException("attributeMap is null");
+ }
+ final String scheme = uri.getScheme();
+ if (scheme == null) {
+ throw new RemotingException("No scheme on remote endpoint URI");
+ }
+ state.requireHold(State.UP);
+ try {
+ final CoreProtocolRegistration registration = protocolMap.get(scheme);
+ if (registration == null) {
+ throw new RemotingException("No handler available for URI scheme \"" + scheme + "\"");
+ }
+ final ProtocolHandlerFactory factory = registration.getProtocolHandlerFactory();
+ try {
+ final CoreSession session = new CoreSession(CoreEndpoint.this);
+ session.initializeClient(factory, uri, attributeMap, createClient(rootListener));
+ sessions.add(session);
+ final Session userSession = session.getUserSession();
+ for (final SessionListener listener : sessionListeners) {
+ executor.execute(new Runnable() {
+ public void run() {
+ listener.handleSessionOpened(userSession);
+ }
+ });
+ }
+ return userSession;
+ } catch (IOException e) {
+ RemotingException rex = new RemotingException("Failed to create protocol handler: " + e.getMessage());
+ rex.setStackTrace(e.getStackTrace());
+ throw rex;
+ }
+ } finally {
+ state.release();
+ }
+ }
+
+ public ProtocolContext openIncomingSession(final ProtocolHandler handler) throws RemotingException {
+ state.requireHold(State.UP);
+ try {
+ final CoreSession session = new CoreSession(CoreEndpoint.this);
+ session.initializeServer(handler, createClient(rootListener));
+ sessions.add(session);
+ return session.getProtocolContext();
+ } finally {
+ state.release();
+ }
+ }
+
+ public Registration registerProtocol(final String scheme, final ProtocolHandlerFactory protocolHandlerFactory) throws RemotingException, IllegalArgumentException {
+ if (scheme == null) {
+ throw new NullPointerException("scheme is null");
+ }
+ if (protocolHandlerFactory == null) {
+ throw new NullPointerException("protocolHandlerFactory is null");
+ }
+ state.requireHold(State.UP);
+ try {
+ final CoreProtocolRegistration registration = new CoreProtocolRegistration(protocolHandlerFactory);
+ protocolMap.put(scheme, registration);
+ return registration;
+ } finally {
+ state.release();
+ }
+ }
+
+ public <I, O> Client<I, O> createClient(RequestListener<I, O> requestListener) {
+ final CoreInboundClient<I, O> inbound = new CoreInboundClient<I, O>(requestListener, executor);
+ final CoreOutboundClient<I, O> outbound = new CoreOutboundClient<I, O>(executor);
+ inbound.initialize(outbound.getContextClient());
+ outbound.initialize(inbound.getClientResponder());
+ return outbound.getUserContext();
+ }
+
+ public <I, O> ClientSource<I, O> createService(RequestListener<I, O> requestListener) {
+ final CoreInboundService<I, O> inbound = new CoreInboundService<I, O>(requestListener, executor);
+ final CoreOutboundService<I, O> outbound = new CoreOutboundService<I, O>(executor);
+ inbound.initialize(outbound.getServiceClient());
+ outbound.initialize(inbound.getServiceResponder());
+ return outbound.getUserContextSource();
+ }
+
+ public void addSessionListener(final SessionListener sessionListener) {
+ // TODO security check
+ sessionListeners.add(sessionListener);
+ }
+
+ public void removeSessionListener(final SessionListener sessionListener) {
+ // TODO security check
+ sessionListeners.remove(sessionListener);
+ }
+
+ void removeSession(CoreSession coreSession) {
+ synchronized (sessions) {
+ if (!sessions.remove(coreSession)) {
+ return;
+ }
+ sessions.notifyAll();
+ }
+ }
+
public final class CoreProtocolRegistration implements Registration {
private final ProtocolHandlerFactory protocolHandlerFactory;
@@ -166,153 +289,4 @@
}
}
}
-
- public final class UserEndpoint implements Endpoint {
-
- public ConcurrentMap<Object, Object> getAttributes() {
- return endpointMap;
- }
-
- public Session openSession(final URI uri, final AttributeMap attributeMap) throws RemotingException {
- if (uri == null) {
- throw new NullPointerException("uri is null");
- }
- if (attributeMap == null) {
- throw new NullPointerException("attributeMap is null");
- }
- final String scheme = uri.getScheme();
- if (scheme == null) {
- throw new RemotingException("No scheme on remote endpoint URI");
- }
- state.requireHold(State.UP);
- try {
- final CoreProtocolRegistration registration = protocolMap.get(scheme);
- if (registration == null) {
- throw new RemotingException("No handler available for URI scheme \"" + scheme + "\"");
- }
- final ProtocolHandlerFactory factory = registration.getProtocolHandlerFactory();
- try {
- final CoreSession session = new CoreSession(CoreEndpoint.this);
- session.initializeClient(factory, uri, attributeMap, createClient(rootListener));
- sessions.add(session);
- final Session userSession = session.getUserSession();
- for (final SessionListener listener : sessionListeners) {
- executor.execute(new Runnable() {
- public void run() {
- listener.handleSessionOpened(userSession);
- }
- });
- }
- return userSession;
- } catch (IOException e) {
- RemotingException rex = new RemotingException("Failed to create protocol handler: " + e.getMessage());
- rex.setStackTrace(e.getStackTrace());
- throw rex;
- }
- } finally {
- state.release();
- }
- }
-
- public ProtocolContext openIncomingSession(final ProtocolHandler handler) throws RemotingException {
- state.requireHold(State.UP);
- try {
- final CoreSession session = new CoreSession(CoreEndpoint.this);
- session.initializeServer(handler, createClient(rootListener));
- sessions.add(session);
- return session.getProtocolContext();
- } finally {
- state.release();
- }
- }
-
- public String getName() {
- return name;
- }
-
- public Registration registerProtocol(final String scheme, final ProtocolHandlerFactory protocolHandlerFactory) throws RemotingException, IllegalArgumentException {
- if (scheme == null) {
- throw new NullPointerException("scheme is null");
- }
- if (protocolHandlerFactory == null) {
- throw new NullPointerException("protocolHandlerFactory is null");
- }
- state.requireHold(State.UP);
- try {
- final CoreProtocolRegistration registration = new CoreProtocolRegistration(protocolHandlerFactory);
- protocolMap.put(scheme, registration);
- return registration;
- } finally {
- state.release();
- }
- }
-
- public <I, O> Client<I, O> createClient(RequestListener<I, O> requestListener) {
- final CoreInboundClient<I, O> inbound = new CoreInboundClient<I, O>(requestListener, executor);
- final CoreOutboundClient<I, O> outbound = new CoreOutboundClient<I, O>(executor);
- inbound.initialize(outbound.getContextClient());
- outbound.initialize(inbound.getClientResponder());
- return outbound.getUserContext();
- }
-
- public <I, O> ClientSource<I, O> createService(RequestListener<I, O> requestListener) {
- final CoreInboundService<I, O> inbound = new CoreInboundService<I, O>(requestListener, executor);
- final CoreOutboundService<I, O> outbound = new CoreOutboundService<I, O>(executor);
- inbound.initialize(outbound.getServiceClient());
- outbound.initialize(inbound.getServiceResponder());
- return outbound.getUserContextSource();
- }
-
- public void addSessionListener(final SessionListener sessionListener) {
- // TODO security check
- sessionListeners.add(sessionListener);
- }
-
- public void removeSessionListener(final SessionListener sessionListener) {
- // TODO security check
- sessionListeners.remove(sessionListener);
- }
-
- public void close() throws RemotingException {
- if (state.transitionHold(State.UP, State.DOWN)) try {
- Iterator<CloseHandler<Endpoint>> it = closeHandlers.iterator();
- while (it.hasNext()) {
- CloseHandler<Endpoint> handler = it.next();
- handler.handleClose(this);
- it.remove();
- }
- } finally {
- state.release();
- }
- }
-
- public void closeImmediate() throws RemotingException {
- if (state.transitionHold(State.UP, State.DOWN)) try {
- Iterator<CloseHandler<Endpoint>> it = closeHandlers.iterator();
- while (it.hasNext()) {
- CloseHandler<Endpoint> handler = it.next();
- handler.handleClose(this);
- it.remove();
- }
- } finally {
- state.release();
- }
- }
-
- public void addCloseHandler(final CloseHandler<Endpoint> closeHandler) {
- if (closeHandler == null) {
- throw new NullPointerException("closeHandler is null");
- }
- final State current = state.getStateHold();
- try {
- if (current != State.DOWN) {
- closeHandlers.add(closeHandler);
- return;
- }
- } finally {
- state.release();
- }
- closeHandler.handleClose(this);
- }
- }
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -235,7 +235,7 @@
}
public String getLocalEndpointName() {
- return endpoint.getUserEndpoint().getName();
+ return endpoint.getName();
}
public String getRemoteEndpointName() {
@@ -312,7 +312,7 @@
}
public String getLocalEndpointName() {
- return endpoint.getUserEndpoint().getName();
+ return endpoint.getName();
}
public void receiveClientClose(ClientIdentifier remoteClientIdentifier, final boolean immediate, final boolean cancel, final boolean interrupt) {
Modified: remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppProtocolSupport.java
===================================================================
--- remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppProtocolSupport.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppProtocolSupport.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -5,6 +5,8 @@
import java.net.SocketAddress;
import java.net.URI;
import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.ExceptionMonitor;
import org.apache.mina.common.IoConnector;
@@ -73,7 +75,12 @@
// Lifecycle
+ private ExecutorService executorService;
+
public void create() throws RemotingException {
+ if (executor == null) {
+ executor = executorService = Executors.newCachedThreadPool();
+ }
ExceptionMonitor.setInstance(new ExceptionMonitor() {
public void exceptionCaught(final Throwable cause) {
// do nothing!
@@ -101,6 +108,10 @@
registration.unregister();
registration = null;
}
+ if (executorService != null) {
+ executorService.shutdown();
+ }
+ executor = executorService = null;
protocolHandlerFactory = null;
}
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppBasicExampleMain.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -10,6 +10,7 @@
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.Remoting;
import org.jboss.cx.remoting.Session;
+import org.jboss.cx.remoting.jrpp.JrppServer;
import org.jboss.cx.remoting.core.security.sasl.Provider;
import org.jboss.cx.remoting.util.AttributeMap;
@@ -23,23 +24,27 @@
final StringRot13RequestListener listener = new StringRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple", listener);
try {
- Remoting.addJrppServer(endpoint, new InetSocketAddress(12345), AttributeMap.EMPTY);
- Session session = endpoint.openSession(new URI("jrpp://localhost:12345"), AttributeMap.EMPTY);
+ final JrppServer jrppServer = Remoting.addJrppServer(endpoint, new InetSocketAddress(12345), AttributeMap.EMPTY);
try {
- final Client<String,String> client = session.getRootClient();
+ Session session = endpoint.openSession(new URI("jrpp://localhost:12345"), AttributeMap.EMPTY);
try {
- final String original = "The Secret Message\n";
- final String result = client.invoke(original);
- System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), result.trim());
+ final Client<String,String> client = session.getRootClient();
+ try {
+ final String original = "The Secret Message\n";
+ final String result = client.invoke(original);
+ System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), result.trim());
+ } finally {
+ client.close();
+ }
} finally {
- client.close();
+ session.close();
}
} finally {
- session.close();
+ jrppServer.stop();
+ jrppServer.destroy();
}
} finally {
- endpoint.close();
+ Remoting.closeEndpoint(endpoint);
}
-
}
}
\ No newline at end of file
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/JrppStreamExampleMain.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -13,6 +13,7 @@
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.Remoting;
import org.jboss.cx.remoting.Session;
+import org.jboss.cx.remoting.jrpp.JrppServer;
import org.jboss.cx.remoting.core.security.sasl.Provider;
import org.jboss.cx.remoting.util.AttributeMap;
@@ -26,37 +27,42 @@
final StreamingRot13RequestListener listener = new StreamingRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple", listener);
try {
- Remoting.addJrppServer(endpoint, new InetSocketAddress(12345), AttributeMap.EMPTY);
- Session session = endpoint.openSession(new URI("jrpp://localhost:12345"), AttributeMap.EMPTY);
+ final JrppServer jrppServer = Remoting.addJrppServer(endpoint, new InetSocketAddress(12345), AttributeMap.EMPTY);
try {
- final Client<Reader,Reader> client = session.getRootClient();
+ Session session = endpoint.openSession(new URI("jrpp://localhost:12345"), AttributeMap.EMPTY);
try {
- final String original = "The Secret Message\n";
- final StringReader originalReader = new StringReader(original);
+ final Client<Reader,Reader> client = session.getRootClient();
try {
- final Reader reader = client.send(originalReader).get();
+ final String original = "The Secret Message\n";
+ final StringReader originalReader = new StringReader(original);
try {
- final BufferedReader bufferedReader = new BufferedReader(reader);
+ final Reader reader = client.send(originalReader).get();
try {
- final String secretLine = bufferedReader.readLine();
- System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), secretLine);
+ final BufferedReader bufferedReader = new BufferedReader(reader);
+ try {
+ final String secretLine = bufferedReader.readLine();
+ System.out.printf("The secret message \"%s\" became \"%s\"!\n", original.trim(), secretLine);
+ } finally {
+ bufferedReader.close();
+ }
} finally {
- bufferedReader.close();
+ reader.close();
}
} finally {
- reader.close();
+ originalReader.close();
}
} finally {
- originalReader.close();
+ client.close();
}
} finally {
- client.close();
+ session.close();
}
} finally {
- session.close();
+ jrppServer.stop();
+ jrppServer.destroy();
}
} finally {
- endpoint.close();
+ Remoting.closeEndpoint(endpoint);
}
}
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -27,7 +27,7 @@
client.close();
}
} finally {
- endpoint.close();
+ Remoting.closeEndpoint(endpoint);
}
}
}
\ No newline at end of file
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -45,7 +45,7 @@
client.close();
}
} finally {
- endpoint.close();
+ Remoting.closeEndpoint(endpoint);
}
}
}
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
--- remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-04-16 12:52:42 UTC (rev 3997)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-04-16 18:08:27 UTC (rev 3998)
@@ -1,10 +1,8 @@
package org.jboss.cx.remoting;
import java.io.IOException;
-import java.net.InetSocketAddress;
import java.net.SocketAddress;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.ConcurrentMap;
import org.jboss.cx.remoting.core.CoreEndpoint;
import org.jboss.cx.remoting.core.protocol.LocalProtocolHandlerFactory;
import org.jboss.cx.remoting.jrpp.JrppProtocolSupport;
@@ -21,51 +19,78 @@
private static final String JRPP_SUPPORT_KEY = "org.jboss.cx.remoting.standalone.jrpp.support";
public static <I, O> Endpoint createEndpoint(String name, RequestListener<I, O> listener) throws IOException {
- final CoreEndpoint coreEndpoint = new CoreEndpoint(name, listener);
- final ExecutorService executorService = Executors.newCachedThreadPool();
- coreEndpoint.setExecutor(executorService);
- coreEndpoint.start();
boolean ok = false;
+ final CoreEndpoint coreEndpoint = new CoreEndpoint();
+ coreEndpoint.setName(name);
+ coreEndpoint.setRootListener(listener);
+ coreEndpoint.create();
try {
- final Endpoint userEndpoint = coreEndpoint.getUserEndpoint();
- LocalProtocolHandlerFactory.addTo(userEndpoint);
- final JrppProtocolSupport jrppProtocolSupport = new JrppProtocolSupport();
- jrppProtocolSupport.setEndpoint(userEndpoint);
- jrppProtocolSupport.setExecutor(executorService);
- jrppProtocolSupport.create();
- jrppProtocolSupport.start();
- userEndpoint.getAttributes().put(JRPP_SUPPORT_KEY, jrppProtocolSupport);
- userEndpoint.addCloseHandler(new CloseHandler<Endpoint>() {
- public void handleClose(final Endpoint closed) {
- executorService.shutdown();
+ coreEndpoint.start();
+ try {
+ LocalProtocolHandlerFactory.addTo(coreEndpoint);
+ final JrppProtocolSupport jrppProtocolSupport = new JrppProtocolSupport();
+ jrppProtocolSupport.setEndpoint(coreEndpoint);
+ jrppProtocolSupport.create();
+ try {
+ jrppProtocolSupport.start();
+ try {
+ final ConcurrentMap<Object, Object> attributes = coreEndpoint.getAttributes();
+ attributes.put(JRPP_SUPPORT_KEY, jrppProtocolSupport);
+ ok = true;
+ return coreEndpoint;
+ } finally {
+ if (! ok) {
+ jrppProtocolSupport.stop();
+ }
+ }
+ } finally {
+ if (! ok) {
+ jrppProtocolSupport.destroy();
+ }
}
- });
- return userEndpoint;
+ } finally {
+ if (! ok) {
+ coreEndpoint.stop();
+ }
+ }
} finally {
if (! ok) {
- coreEndpoint.stop();
+ coreEndpoint.destroy();
}
}
}
+ public static void closeEndpoint(Endpoint endpoint) {
+ if (endpoint instanceof CoreEndpoint) {
+ final CoreEndpoint coreEndpoint = (CoreEndpoint) endpoint;
+ final ConcurrentMap<Object, Object> attributes = coreEndpoint.getAttributes();
+ final JrppProtocolSupport jrppProtocolSupport = (JrppProtocolSupport) attributes.get(JRPP_SUPPORT_KEY);
+ coreEndpoint.stop();
+ coreEndpoint.destroy();
+ if (jrppProtocolSupport != null) {
+ jrppProtocolSupport.stop();
+ jrppProtocolSupport.destroy();
+ }
+ }
+ }
+
public static JrppServer addJrppServer(Endpoint endpoint, SocketAddress address, AttributeMap attributeMap) throws IOException {
+ boolean ok = false;
final JrppServer jrppServer = new JrppServer();
jrppServer.setProtocolSupport((JrppProtocolSupport) endpoint.getAttributes().get(JRPP_SUPPORT_KEY));
- jrppServer.setSocketAddress(new InetSocketAddress(12345));
- jrppServer.setAttributeMap(AttributeMap.EMPTY);
+ jrppServer.setSocketAddress(address);
+ jrppServer.setAttributeMap(attributeMap);
jrppServer.setEndpoint(endpoint);
jrppServer.create();
- jrppServer.start();
- endpoint.addCloseHandler(new CloseHandler<Endpoint>() {
- public void handleClose(final Endpoint closed) {
- try {
- jrppServer.stop();
- } finally {
- jrppServer.destroy();
- }
+ try {
+ jrppServer.start();
+ ok = true;
+ return jrppServer;
+ } finally {
+ if (! ok) {
+ jrppServer.destroy();
}
- });
- return jrppServer;
+ }
}
// privates
16 years, 11 months