You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2011/11/20 21:39:49 UTC
svn commit: r1204240 - in
/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api:
FutureResponseImpl.java FutureStreamResponseImpl.java
StartTlsFutureResponse.java
Author: norman
Date: Sun Nov 20 20:39:49 2011
New Revision: 1204240
URL: http://svn.apache.org/viewvc?rev=1204240&view=rev
Log:
Add helper classes which transform a AbstractResponse to a FutureResponse
Added:
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureResponseImpl.java (with props)
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureStreamResponseImpl.java (with props)
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/StartTlsFutureResponse.java (with props)
Added: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureResponseImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureResponseImpl.java?rev=1204240&view=auto
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureResponseImpl.java (added)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureResponseImpl.java Sun Nov 20 20:39:49 2011
@@ -0,0 +1,139 @@
+/****************************************************************
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * {@link FutureResponse} implementation which wraps a {@link AbstractResponse} implementation
+ *
+ *
+ */
+public class FutureResponseImpl extends AbstractResponse implements FutureResponse{
+
+ private final AbstractResponse response;
+ private boolean ready = false;
+ private List<ResponseListener> listeners;
+ private int waiters;
+
+ public FutureResponseImpl(AbstractResponse response) {
+ this.response = response;
+ }
+
+ protected final synchronized void checkReady() {
+ while (!ready) {
+ try {
+ waiters++;
+ wait();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ } finally {
+ waiters--;
+ }
+ }
+ }
+ @Override
+ public synchronized void addListener(ResponseListener listener) {
+ if (ready) {
+ listener.onResponse(this);
+ } else {
+ if (listeners == null) {
+ listeners = new ArrayList<ResponseListener>();
+ }
+ listeners.add(listener);
+ }
+ }
+
+ @Override
+ public synchronized void removeListener(ResponseListener listener) {
+ if (listeners != null) {
+ listeners.remove(listener);
+ }
+ }
+
+ @Override
+ public synchronized boolean isReady() {
+ return ready;
+ }
+
+ public synchronized void markReady() {
+ if (!ready) {
+ ready = true;
+
+ if (waiters > 0) {
+ notifyAll();
+ }
+
+ for (ResponseListener listener: listeners) {
+ listener.onResponse(this);
+ }
+ listeners = null;
+ }
+ }
+
+ @Override
+ public List<CharSequence> getLines() {
+ checkReady();
+ return response.getLines();
+ }
+
+ @Override
+ public synchronized void appendLine(CharSequence line) {
+ if (ready) {
+ throw new IllegalStateException("FutureSMTPResponse MUST NOT get modified after its ready");
+ }
+ response.appendLine(line);
+ }
+
+ @Override
+ public String getRetCode() {
+ checkReady();
+ return response.getRetCode();
+ }
+
+ @Override
+ public synchronized void setRetCode(String retCode) {
+ if (ready) {
+ throw new IllegalStateException("FutureSMTPResponse MUST NOT get modified after its ready");
+ }
+ response.setRetCode(retCode);
+ }
+
+ @Override
+ public boolean isEndSession() {
+ checkReady();
+ return response.isEndSession();
+ }
+
+ @Override
+ public synchronized void setEndSession(boolean endSession) {
+ if (ready) {
+ throw new IllegalStateException("FutureSMTPResponse MUST NOT get modified after its ready");
+ }
+ response.setEndSession(endSession);
+ }
+
+ @Override
+ public synchronized String toString() {
+ return response.toString();
+ }
+
+}
Propchange: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureResponseImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureStreamResponseImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureStreamResponseImpl.java?rev=1204240&view=auto
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureStreamResponseImpl.java (added)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureStreamResponseImpl.java Sun Nov 20 20:39:49 2011
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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;
+
+import java.io.InputStream;
+
+public class FutureStreamResponseImpl extends FutureResponseImpl implements StreamResponse{
+
+ private InputStream in;
+ public FutureStreamResponseImpl(AbstractResponse response) {
+ super(response);
+ if ((response instanceof StreamResponse) == false) {
+ throw new IllegalArgumentException("Given Response must be a StreamResponse");
+ }
+ }
+
+ public synchronized void setInputStream(InputStream in) {
+ this.in = in;
+ }
+ @Override
+ public InputStream getStream() {
+ checkReady();
+ return in;
+ }
+
+}
Propchange: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/FutureStreamResponseImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/StartTlsFutureResponse.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/StartTlsFutureResponse.java?rev=1204240&view=auto
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/StartTlsFutureResponse.java (added)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/StartTlsFutureResponse.java Sun Nov 20 20:39:49 2011
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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;
+
+public class StartTlsFutureResponse extends FutureResponseImpl implements StartTlsResponse{
+
+ public StartTlsFutureResponse(AbstractResponse response) {
+ super(response);
+ }
+
+}
Propchange: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/StartTlsFutureResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org