james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1226242 - in /james/protocols/trunk: api/src/main/java/org/apache/james/protocols/api/ api/src/main/java/org/apache/james/protocols/api/future/ api/src/main/java/org/apache/james/protocols/api/handler/ api/src/test/java/org/apache/james/pr...
Date Sun, 01 Jan 2012 12:12:30 GMT
Author: norman
Date: Sun Jan  1 12:12:30 2012
New Revision: 1226242

URL: http://svn.apache.org/viewvc?rev=1226242&view=rev
Log:
Move future classes to extra package

Added:
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponse.java
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponseImpl.java
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStartTlsResponse.java
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStreamResponseImpl.java
Removed:
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureResponse.java
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureResponseImpl.java
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureStreamResponseImpl.java
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/StartTlsFutureResponse.java
Modified:
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java
    james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java
    james/protocols/trunk/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java
    james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java

Modified: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java?rev=1226242&r1=1226241&r2=1226242&view=diff
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java
(original)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractProtocolTransport.java
Sun Jan  1 12:12:30 2012
@@ -25,7 +25,8 @@ import java.util.List;
 import java.util.Queue;
 import java.util.concurrent.LinkedBlockingQueue;
 
-import org.apache.james.protocols.api.FutureResponse.ResponseListener;
+import org.apache.james.protocols.api.future.FutureResponse;
+import org.apache.james.protocols.api.future.FutureResponse.ResponseListener;
 
 
 /**

Added: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponse.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponse.java?rev=1226242&view=auto
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponse.java
(added)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponse.java
Sun Jan  1 12:12:30 2012
@@ -0,0 +1,68 @@
+/****************************************************************
+ * 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.james.protocols.api.future;
+
+import org.apache.james.protocols.api.Response;
+
+/**
+ * An special {@link Response} which allows to populate it in an async fashion. It also allows
to register listeners which will get notified once the 
+ * {@link FutureResponse} is ready
+ * 
+ *
+ */
+public interface FutureResponse extends Response{
+
+    /**
+     * Add a {@link ResponseListener} which will get notified once {@link #isReady()} is
true
+     * 
+     * @param listener
+     */
+    public void addListener(ResponseListener listener);
+    
+    /**
+     * Remote a {@link ResponseListener}
+     * 
+     * @param listener
+     */
+    public void removeListener(ResponseListener listener);
+    
+    /**
+     * Return <code>true</code> once the {@link FutureResponse} is ready and
calling any of the get methods will not block any more.
+     * 
+     * @return ready
+     */
+    public boolean isReady();
+    
+    
+    /**
+     * Listener which will get notified once the {@link FutureResponse#isReady()} returns
<code>true</code>
+     * 
+     *
+     */
+    public interface ResponseListener {
+
+        /**
+         * The {@link FutureResponse} is ready for processing
+         * 
+         * @param response
+         */
+        public void onResponse(FutureResponse response);
+    }
+}

Added: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponseImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponseImpl.java?rev=1226242&view=auto
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponseImpl.java
(added)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureResponseImpl.java
Sun Jan  1 12:12:30 2012
@@ -0,0 +1,162 @@
+/****************************************************************
+ * 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.james.protocols.api.future;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.protocols.api.AbstractResponse;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.logger.Logger;
+
+/**
+ * {@link FutureResponse} implementation which wraps a {@link AbstractResponse} implementation
+ * 
+ *
+ */
+public class FutureResponseImpl implements FutureResponse{
+    
+    private final Logger logger;
+
+    public FutureResponseImpl() {
+        this(null);
+    }
+    
+    public FutureResponseImpl(Logger logger) {
+        this.logger = logger;
+    }
+    
+    protected Response response;
+    private List<ResponseListener> listeners;
+    private int waiters;
+
+    protected final synchronized void checkReady() {
+        while (!isReady()) {
+            try {
+                waiters++;
+                wait();
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+            } finally {
+                waiters--;
+            }
+        }
+    }
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.protocols.api.FutureResponse#addListener(org.apache.james.protocols.api.FutureResponse.ResponseListener)
+     */
+    public synchronized void addListener(ResponseListener listener) {
+        if (isReady()) {
+            listener.onResponse(this);
+        } else {
+            if (listeners == null) {
+                listeners = new ArrayList<ResponseListener>();
+            }
+            listeners.add(listener);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.protocols.api.FutureResponse#removeListener(org.apache.james.protocols.api.FutureResponse.ResponseListener)
+     */
+    public synchronized void removeListener(ResponseListener listener) {
+        if (!isReady()) {
+            if (listeners != null) {
+                listeners.remove(listener);
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.protocols.api.FutureResponse#isReady()
+     */
+    public synchronized boolean isReady() {
+        return response != null;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.protocols.api.Response#getLines()
+     */
+    public List<CharSequence> getLines() {
+        checkReady();
+        return response.getLines();
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.protocols.api.Response#getRetCode()
+     */
+    public String getRetCode() {
+        checkReady();
+        return response.getRetCode();
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.protocols.api.Response#isEndSession()
+     */
+    public boolean isEndSession() {
+        checkReady();
+        return response.isEndSession();
+    }
+
+    @Override
+    public synchronized String toString() {
+        checkReady();
+        return response.toString();
+    }
+    
+    public void setResponse(Response response) {
+        boolean fire = false;
+        synchronized (this) {
+            if (!isReady()) {
+                this.response = response;
+                fire = listeners != null;
+
+                if (waiters > 0) {
+                    notifyAll();
+                }
+            }
+        }
+
+        if (fire) {
+            for (ResponseListener listener : listeners) {
+                try {
+                    listener.onResponse(this);
+                } catch (Throwable e) {
+                    if (logger != null) {
+                        logger.warn("An exception was thrown by the listener " + listener,
e);
+                    } else {
+                        e.printStackTrace();
+                    }
+                }
+            }
+            listeners = null;
+            
+        }
+    }
+
+}

Added: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStartTlsResponse.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStartTlsResponse.java?rev=1226242&view=auto
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStartTlsResponse.java
(added)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStartTlsResponse.java
Sun Jan  1 12:12:30 2012
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.james.protocols.api.future;
+
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.StartTlsResponse;
+
+public class FutureStartTlsResponse extends FutureResponseImpl implements StartTlsResponse{
+
+
+    /**
+     * Set the {@link StartTlsResponse} to wrap. If a non {@link StartTlsResponse} is set
this implementation will throw an {@link IllegalArgumentException}
+     * 
+     */
+    @Override
+    public void setResponse(Response response) {
+        if (response instanceof StartTlsResponse) {
+            super.setResponse(response);
+        } else {
+            throw new IllegalArgumentException("Response MUST be of type " + StartTlsResponse.class.getName());
+        }
+    }
+
+}

Added: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStreamResponseImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStreamResponseImpl.java?rev=1226242&view=auto
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStreamResponseImpl.java
(added)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/future/FutureStreamResponseImpl.java
Sun Jan  1 12:12:30 2012
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.james.protocols.api.future;
+
+import java.io.InputStream;
+
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.StreamResponse;
+
+public class FutureStreamResponseImpl extends FutureResponseImpl implements StreamResponse{
+
+    /**
+     * Set the {@link StreamResponse} to wrap. If a non {@link StreamResponse} is set this
implementation will throw an {@link IllegalArgumentException}
+     * 
+     */
+    @Override
+    public void setResponse(Response response) {
+        if (response instanceof StreamResponse) {
+            super.setResponse(response);
+        } else {
+            throw new IllegalArgumentException("Response MUST be of type " + StreamResponse.class.getName());
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.protocols.api.StreamResponse#getStream()
+     */
+    public InputStream getStream() {
+        checkReady();
+        return ((StreamResponse) response).getStream();
+        
+    }
+}

Modified: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java?rev=1226242&r1=1226241&r2=1226242&view=diff
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java
(original)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java
Sun Jan  1 12:12:30 2012
@@ -30,10 +30,10 @@ import java.util.List;
 import java.util.Locale;
 
 import org.apache.james.protocols.api.BaseRequest;
-import org.apache.james.protocols.api.FutureResponse;
 import org.apache.james.protocols.api.ProtocolSession;
 import org.apache.james.protocols.api.Request;
 import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.future.FutureResponse;
 
 
 

Modified: james/protocols/trunk/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java?rev=1226242&r1=1226241&r2=1226242&view=diff
==============================================================================
--- james/protocols/trunk/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java
(original)
+++ james/protocols/trunk/api/src/test/java/org/apache/james/protocols/api/AbstractProtocolTransportTest.java
Sun Jan  1 12:12:30 2012
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.CountDownLatch;
 
+import org.apache.james.protocols.api.future.FutureResponseImpl;
 import org.apache.james.protocols.api.handler.LineHandler;
 import org.junit.Test;
 

Modified: james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java?rev=1226242&r1=1226241&r2=1226242&view=diff
==============================================================================
--- james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java
(original)
+++ james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java
Sun Jan  1 12:12:30 2012
@@ -24,12 +24,12 @@ import java.util.List;
 import javax.net.ssl.SSLEngine;
 
 import org.apache.james.protocols.api.ProtocolSessionImpl;
-import org.apache.james.protocols.api.FutureResponse;
 import org.apache.james.protocols.api.Protocol;
 import org.apache.james.protocols.api.ProtocolSession;
 import org.apache.james.protocols.api.ProtocolTransport;
 import org.apache.james.protocols.api.Response;
 import org.apache.james.protocols.api.Encryption;
+import org.apache.james.protocols.api.future.FutureResponse;
 import org.apache.james.protocols.api.handler.ConnectHandler;
 import org.apache.james.protocols.api.handler.DisconnectHandler;
 import org.apache.james.protocols.api.handler.LineHandler;



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message