labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r658566 - in /labs/vysper/src: main/java/org/apache/vysper/xmpp/delivery/ main/java/org/apache/vysper/xmpp/delivery/failure/ main/java/org/apache/vysper/xmpp/modules/core/base/handler/ test/java/org/apache/vysper/xmpp/delivery/
Date Wed, 21 May 2008 06:45:13 GMT
Author: berndf
Date: Tue May 20 23:45:12 2008
New Revision: 658566

URL: http://svn.apache.org/viewvc?rev=658566&view=rev
Log:
[vysper] introduce failure strategy,

Added:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachableException.java
      - copied, changed from r657983, labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java
Removed:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java
Modified:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/RecordingStanzaRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
    labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java?rev=658566&r1=658565&r2=658566&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java Tue
May 20 23:45:12 2008
@@ -46,7 +46,7 @@
         this.executor = new ThreadPoolExecutor(coreThreadCount, maxThreadCount, threadTimeoutSeconds,
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
     }
     
-    public void relay(Entity receiver, Stanza stanza) throws DeliveryException {
+    public void relay(Entity receiver, Stanza stanza, DeliveryFailureStrategy deliveryFailureStrategy)
throws DeliveryException {
         Future<RelayResult> resultFuture = executor.submit(new Relay(receiver, stanza));
     }
 
@@ -76,7 +76,7 @@
                 List<SessionContext> receivingSessions = resourceRegistry.getSessions(receiver);
                 if (receivingSessions == null || receivingSessions.size() == 0) {
                     System.out.println("S: #E# cannot relay to " + receiver.getFullQualifiedName());
-                    return new RelayResult(new LocalRecipientNotReachable());
+                    return new RelayResult(new LocalRecipientNotReachableException());
                 }
                 for (SessionContext sessionContext : receivingSessions) {
                     StanzaWriter stanzaWriter = null;

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java?rev=658566&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java
(added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java
Tue May 20 23:45:12 2008
@@ -0,0 +1,34 @@
+/***********************************************************************
+ * Copyright (c) 2006-2008 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.vysper.xmpp.delivery;
+ 
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+ 
+/**
+ * there are many reasons why a stanza may fail to deliver: remote server not answering,
local addressee has
+ * become unavailable, the server has no more resources to process etc.
+ * what to do in this case also depends on the context. if the server intends to send out
a presence notification,
+ * an unavailable client might be ignored, but if a message stanza fails to deliver, the
sender might wants to be
+ * notified. 
+ */
+public interface DeliveryFailureStrategy {
+ 
+    public void process(Stanza failedToDeliverStanza, ServerRuntimeContext serverRuntimeContext,
DeliveryException deliveryException);
+    
+}

Copied: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachableException.java
(from r657983, labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java)
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachableException.java?p2=labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachableException.java&p1=labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java&r1=657983&r2=658566&rev=658566&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachableException.java
Tue May 20 23:45:12 2008
@@ -2,20 +2,20 @@
 
 /**
  */
-public class LocalRecipientNotReachable extends DeliveryException {
-    public LocalRecipientNotReachable() {
+public class LocalRecipientNotReachableException extends DeliveryException {
+    public LocalRecipientNotReachableException() {
         super();
     }
 
-    public LocalRecipientNotReachable(String string) {
+    public LocalRecipientNotReachableException(String string) {
         super(string);
     }
 
-    public LocalRecipientNotReachable(String string, Throwable throwable) {
+    public LocalRecipientNotReachableException(String string, Throwable throwable) {
         super(string, throwable);
     }
 
-    public LocalRecipientNotReachable(Throwable throwable) {
+    public LocalRecipientNotReachableException(Throwable throwable) {
         super(throwable);
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java?rev=658566&r1=658565&r2=658566&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java Tue May
20 23:45:12 2008
@@ -19,6 +19,7 @@
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.server.ServerRuntimeContext;
 import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
 
 /**
  * relays stanzas. handles message itself, routes to another server/domain or delivers locally.
@@ -41,7 +42,7 @@
         this.serverRuntimeContext = serverRuntimeContext;
     }
 
-    public void relay(Entity receiver, Stanza stanza) throws DeliveryException {
+    public void relay(Entity receiver, Stanza stanza, DeliveryFailureStrategy deliveryFailureStrategy)
throws DeliveryException {
         if (receiver == null || !receiver.isNodeSet()) {
             // TODO handle by server
             
@@ -58,10 +59,10 @@
         boolean relayToExternal = serverRuntimeContext.getServerFeatures().isRelayingToFederationServers();
 
         if (domain.equals(serverRuntimeContext.getServerEnitity().getDomain())) {
-            internalRelay.relay(receiver, stanza);
+            internalRelay.relay(receiver, stanza, new IgnoreFailureStrategy());
         } else {
             if (!relayToExternal) throw new IllegalStateException("this server is not relaying
to external currently");
-            externalRelay.relay(receiver, stanza);
+            externalRelay.relay(receiver, stanza, new IgnoreFailureStrategy());
         }
     }
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/RecordingStanzaRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/RecordingStanzaRelay.java?rev=658566&r1=658565&r2=658566&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/RecordingStanzaRelay.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/RecordingStanzaRelay.java Tue
May 20 23:45:12 2008
@@ -31,7 +31,7 @@
     private final ArrayList<Pair> entityStanzaPairs = new ArrayList<Pair>();
     private boolean acceptingMode = true;
 
-    public void relay(Entity receiver, Stanza stanza) throws DeliveryException {
+    public void relay(Entity receiver, Stanza stanza, DeliveryFailureStrategy deliveryFailureStrategy)
throws DeliveryException {
         if (!acceptingMode) return;
         entityStanzaPairs.add(new Pair(receiver, stanza));
     }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java?rev=658566&r1=658565&r2=658566&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java Tue
May 20 23:45:12 2008
@@ -34,7 +34,7 @@
         receiverMap.put(receiverID, receiver);
     }
 
-    public void relay(Entity receiver, Stanza stanza) throws DeliveryException {
+    public void relay(Entity receiver, Stanza stanza, DeliveryFailureStrategy deliveryFailureStrategy)
throws DeliveryException {
         if (receiver == null) throw new DeliveryException("receiver cannot be NULL");
         if (receiverMap.get(receiver) == null) throw new DeliveryException("cannot find receiver"
+ receiver.getFullQualifiedName());
         receiverMap.get(receiver).deliver(stanza);

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaRelay.java?rev=658566&r1=658565&r2=658566&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaRelay.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaRelay.java Tue May 20
23:45:12 2008
@@ -25,6 +25,6 @@
  */
 public interface StanzaRelay {
 
-    public void relay(Entity receiver, Stanza stanza) throws DeliveryException;
+    public void relay(Entity receiver, Stanza stanza, DeliveryFailureStrategy deliveryFailureStrategy)
throws DeliveryException;
 
 }

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java?rev=658566&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java
(added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java
Tue May 20 23:45:12 2008
@@ -0,0 +1,32 @@
+/***********************************************************************
+ * Copyright (c) 2006-2008 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.vysper.xmpp.delivery.failure;
+
+import org.apache.vysper.xmpp.delivery.DeliveryFailureStrategy;
+import org.apache.vysper.xmpp.delivery.DeliveryException;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+
+/**
+ */
+public class IgnoreFailureStrategy implements DeliveryFailureStrategy {
+
+    public void process(Stanza failedToDeliverStanza, ServerRuntimeContext serverRuntimeContext,
DeliveryException deliveryException) {
+        // do nothing                                                                   
                       
+    }
+}

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java?rev=658566&r1=658565&r2=658566&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
Tue May 20 23:45:12 2008
@@ -19,6 +19,7 @@
 
 import org.apache.vysper.xmpp.addressing.Entity;
 import org.apache.vysper.xmpp.delivery.StanzaRelay;
+import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
 import org.apache.vysper.xmpp.server.SessionContext;
 import org.apache.vysper.xmpp.stanza.MessageStanza;
 import org.apache.vysper.xmpp.stanza.Stanza;
@@ -78,7 +79,7 @@
         
         StanzaRelay stanzaRelay = sessionContext.getServerRuntimeContext().getStanzaRelay();
         try {
-            stanzaRelay.relay(to, stanza);
+            stanzaRelay.relay(to, stanza, new IgnoreFailureStrategy());
         } catch (Exception e) {
             // TODO return error stanza
             e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java?rev=658566&r1=658565&r2=658566&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
Tue May 20 23:45:12 2008
@@ -25,6 +25,7 @@
 import org.apache.vysper.xmpp.addressing.EntityImpl;
 import org.apache.vysper.xmpp.delivery.DeliveryException;
 import org.apache.vysper.xmpp.delivery.StanzaRelay;
+import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
 import org.apache.vysper.xmpp.protocol.NamespaceURIs;
 import org.apache.vysper.xmpp.resourcebinding.ResourceRegistry;
 import org.apache.vysper.xmpp.resourcebinding.ResourceState;
@@ -397,7 +398,7 @@
 
 		// relay the stanza to the contact's server
 		try {
-			stanzaRelay.relay(stanza.getTo(), stanza);
+			stanzaRelay.relay(stanza.getTo(), stanza, new IgnoreFailureStrategy());
 		} catch (DeliveryException e) {
 			e.printStackTrace();
 		}
@@ -413,7 +414,7 @@
 					sessionContext.nextSequenceValue(), contact.getBareJID(),
 					"none");
 			try {
-				stanzaRelay.relay(userResource, push);
+				stanzaRelay.relay(userResource, push, new IgnoreFailureStrategy());
 			} catch (DeliveryException e) {
 				e.printStackTrace();
 			}
@@ -515,7 +516,7 @@
 	private void relayStanza(Entity receiver, Stanza stanza,
 			SessionContext sessionContext) {
 		try {
-			sessionContext.getServerRuntimeContext().getStanzaRelay().relay(receiver, stanza);
+			sessionContext.getServerRuntimeContext().getStanzaRelay().relay(receiver, stanza, new
IgnoreFailureStrategy());
 		} catch (DeliveryException e) {
 			e.printStackTrace();
 		}

Modified: labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java?rev=658566&r1=658565&r2=658566&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java
(original)
+++ labs/vysper/src/test/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelayTestCase.java
Tue May 20 23:45:12 2008
@@ -23,6 +23,7 @@
 import org.apache.vysper.xmpp.stanza.StanzaBuilder;
 import org.apache.vysper.xmpp.stanza.Stanza;
 import org.apache.vysper.xmpp.xmlfragment.XMLSemanticError;
+import org.apache.vysper.xmpp.delivery.failure.IgnoreFailureStrategy;
 import junit.framework.TestCase;
 
 /**
@@ -41,7 +42,7 @@
         Stanza stanza = StanzaBuilder.createMessageStanza(fromEntity, toEntity, "en", "Hello").getFinalStanza();
 
         try {
-            stanzaRelay.relay(toEntity, stanza);
+            stanzaRelay.relay(toEntity, stanza, new IgnoreFailureStrategy());
             try { Thread.sleep(60); } catch (InterruptedException e) { ; } // eventually,
this gets delivered
             Stanza recordedStanza = sessionContext.getRecordedResponse();
             assertNotNull("stanza delivered", recordedStanza);
@@ -61,7 +62,7 @@
         Stanza stanza = StanzaBuilder.createMessageStanza(fromEntity, toEntity, "en", "Hello").getFinalStanza();
 
         try {
-            stanzaRelay.relay(toEntity, stanza);
+            stanzaRelay.relay(toEntity, stanza, new IgnoreFailureStrategy());
             try { Thread.sleep(60); } catch (InterruptedException e) { ; } // eventually,
this gets delivered
             Stanza recordedStanza = sessionContext.getRecordedResponse();
             assertNull("stanza not delivered to unbound", recordedStanza);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message