labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r653602 - in /labs/vysper/src: main/config/ main/java/org/apache/vysper/xmpp/modules/core/base/handler/ main/java/org/apache/vysper/xmpp/resourcebinding/ main/java/org/apache/vysper/xmpp/stanza/ test/java/org/apache/vysper/smack/
Date Mon, 05 May 2008 21:02:53 GMT
Author: berndf
Date: Mon May  5 14:02:53 2008
New Revision: 653602

URL: http://svn.apache.org/viewvc?rev=653602&view=rev
Log:
[vysper] simplify presence handling, reuse existing PresenceStanza & PresenceStanzaType,
handle presence status change & unavailability

Modified:
    labs/vysper/src/main/config/spring-config.xml
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanzaType.java
    labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java

Modified: labs/vysper/src/main/config/spring-config.xml
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/config/spring-config.xml?rev=653602&r1=653601&r2=653602&view=diff
==============================================================================
--- labs/vysper/src/main/config/spring-config.xml (original)
+++ labs/vysper/src/main/config/spring-config.xml Mon May  5 14:02:53 2008
@@ -85,6 +85,7 @@
                     <map>
                         <entry key="user1@vysper.org" value="password1" />
                         <entry key="user2@vysper.org" value="password1" />
+                        <entry key="user3@vysper.org" value="password1" />
                     </map>
                 </constructor-arg>
             </bean>

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=653602&r1=653601&r2=653602&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
Mon May  5 14:02:53 2008
@@ -35,6 +35,7 @@
 import org.apache.vysper.xmpp.stanza.StanzaBuilder;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
 import org.apache.vysper.xmpp.stanza.XMPPCoreStanzaVerifier;
+import org.apache.vysper.xmpp.stanza.PresenceStanzaType;
 
 /**
  * handling presence stanzas
@@ -50,77 +51,134 @@
 
 	protected Stanza executeCore(XMPPCoreStanza stanza,
 			SessionContext sessionContext) {
-		// TODO: either use the resource associated with the session
+        PresenceStanza presenceStanza = (PresenceStanza)stanza;
+        
+        // TODO: either use the resource associated with the session
 		// (initiatingEntity)
 		// or in case of multiple resources, use the from attribute or return an
 		// error if the from attribute is not present.
 		Entity initiatingEntity = sessionContext.getInitiatingEntity();
-		XMPPCoreStanzaVerifier verifier = stanza.getCoreVerifier();
+		XMPPCoreStanzaVerifier verifier = presenceStanza.getCoreVerifier();
+        ResourceRegistry registry = sessionContext.getServerRuntimeContext().getResourceRegistry();
 
-		boolean hasFrom = verifier.attributePresent("from");
-		boolean hasTo = verifier.attributePresent("to");
-		boolean hasType = verifier.attributePresent("type");
-
-		if (!hasTo && !hasType) {
-			// RFC3921bis-04#4.2.2 Initial Presence
-			handleOutboundInitialPresence(stanza, sessionContext,
-					initiatingEntity);
-		} else if (hasType && hasTo && !hasFrom
-				&& !sessionContext.isServerToServer()) {
+        boolean hasFrom = verifier.attributePresent("from");
+        boolean hasTo = verifier.attributePresent("to");
+        boolean hasType = verifier.attributePresent("type");
+        PresenceStanzaType type = presenceStanza.getPresenceType();
+
+        if (!hasTo && !hasType) {
+            ResourceState resourceState = registry.getResourceState(registry.getFirstResourceForSession(sessionContext));
+
+            if (resourceState != null && resourceState == ResourceState.AVAILABLE)
{
+                handleOutboundPresenceUpdate(presenceStanza, sessionContext, registry, initiatingEntity);
+            } else {
+                // RFC3921bis-04#4.2.2 Initial Presence
+                handleOutboundInitialPresence(presenceStanza, sessionContext, registry, initiatingEntity);
+            }
+
+        } else if (hasType && hasTo && !hasFrom && !sessionContext.isServerToServer())
{
 			// this is an outbound subscription
 			// request/approval/cancellation/unsubscription
 			// stamp it with the bare JID of the user
 			Entity user = initiatingEntity;
-			XMPPCoreStanza stampedStanza = buildPresenceStanza(user
-					.getBareJID(), stanza.getTo().getBareJID(), stanza
-					.getType());
-			String type = stanza.getType();
-			if ("subscribe".equals(type)) {
-				// RFC3921bis-04#3.1.2
-				handleOutboundSubscriptionRequest(stampedStanza, sessionContext);
-			} else if ("unsubscribe".equals(type)) {
-				// RFC3921bis-04#3.3.2
-				handleOutboundUnsubscription(stampedStanza, sessionContext);
-			} else if ("subscribed".equals(type)) {
-				// RFC3921bis-04#3.1.5
-				handleOutboundSubscriptionApproval(stampedStanza,
-						sessionContext);
-			} else if ("unsubscribed".equals(type)) {
-				// RFC3921bis-04#3.2.2
-				handleOutboundSubscriptionCancellation(stampedStanza,
-						sessionContext);
-			}
+			PresenceStanza stampedStanza = buildPresenceStanza(user.getBareJID(), 
+                    presenceStanza.getTo().getBareJID(), presenceStanza.getType());
+
+            switch (type) {
+
+                case ERROR:
+                    throw new RuntimeException("not implemented yet");
+                    
+                case PROBE:
+                    throw new RuntimeException("not implemented yet");
+                
+                case SUBSCRIBE:
+                    // RFC3921bis-04#3.1.2
+                    handleOutboundSubscriptionRequest(stampedStanza, sessionContext, registry);
+                    break;
+                
+                case SUBSCRIBED:
+                    // RFC3921bis-04#3.1.5
+                    handleOutboundSubscriptionApproval(stampedStanza, sessionContext, registry);
+                    break;
+                
+                case UNAVAILABLE:
+                    throw new RuntimeException("not implemented yet");
+                
+                case UNSUBSCRIBE:
+                    // RFC3921bis-04#3.3.2
+                    handleOutboundUnsubscription(stampedStanza, sessionContext, registry);
+                    break;
+                
+                case UNSUBSCRIBED:
+                    // RFC3921bis-04#3.2.2
+                    handleOutboundSubscriptionCancellation(stampedStanza, sessionContext,
registry);
+                    break;
+                
+                default:
+                    throw new RuntimeException("unhandled case " + type.value());
+            }
+            
 		} else if (hasFrom && hasTo && !hasType) {
 			// RFC3921bis-04#4.2.3
-			handleInboundInitialPresence(stanza, sessionContext);
-		} else if (hasFrom && hasTo && hasType) {
-			String type = stanza.getType();
-			if ("subscribe".equals(type)) {
-				// RFC3921bis-04#3.1.3
-				return handleInboundSubscriptionRequest(stanza, sessionContext);
-			} else if ("subscribed".equals(type)) {
-				// RFC3921bis-04#3.1.6
-				return handleInboundSubscriptionApproval(stanza, sessionContext);
-			} else if ("unsubscribed".equals(type)) {
-				// RFC3921bis-04#3.2.3
-				handleInboundSubscriptionCancellation(stanza, sessionContext);
-			} else if ("unsubscribe".equals(type)) {
-				// RFC3921bis-04#3.3.3
-				handleInboundUnsubscription(stanza, sessionContext);
-			} else if ("probe".equals(type)) {
-				handleInboundPresenceProbe(stanza, sessionContext);
-			}
+			handleInboundInitialPresence(presenceStanza, sessionContext, registry);
+		
+        } else if (hasFrom && hasTo && hasType) {
+
+            switch (type) {
+
+                case ERROR:
+                    throw new RuntimeException("not implemented yet");
+                    
+                case PROBE:
+                    handleInboundPresenceProbe(presenceStanza, sessionContext, registry);
+
+                case SUBSCRIBE:
+                    // RFC3921bis-04#3.1.3
+                    return handleInboundSubscriptionRequest(presenceStanza, sessionContext,
registry);
+
+                case SUBSCRIBED:
+                    // RFC3921bis-04#3.1.6
+                    return handleInboundSubscriptionApproval(presenceStanza, sessionContext,
registry);
+
+                case UNAVAILABLE:
+                    throw new RuntimeException("not implemented yet");
+
+                case UNSUBSCRIBE:
+                    // RFC3921bis-04#3.3.3
+                    handleInboundUnsubscription(presenceStanza, sessionContext, registry);
+
+                case UNSUBSCRIBED:
+                    // RFC3921bis-04#3.2.3
+                    handleInboundSubscriptionCancellation(presenceStanza, sessionContext,
registry);
+
+                default:
+                    throw new RuntimeException("unhandled case " + type.value());
+                    
+            }
 
 		} else if (hasFrom && hasTo) {
-
-		}
+            throw new RuntimeException("unhandled presence stanza");
+        } else if (!hasFrom && hasType && type == PresenceStanzaType.UNAVAILABLE)
{
+            handleInboundUnavailable(presenceStanza, sessionContext);
+        } else {
+            System.err.println("unhandled presence case");
+        }
 
 		return null;
 	}
 
-	@SpecCompliant(spec = "RFC3921bis-04", section = "4.3.2")
-	private XMPPCoreStanza handleInboundPresenceProbe(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
+    private void handleOutboundPresenceUpdate(PresenceStanza stanza, SessionContext sessionContext,

+                                              ResourceRegistry registry, Entity initiatingEntity)
{
+        System.out.println("C: has updated his presence");
+    }
+
+    private void handleInboundUnavailable(PresenceStanza presenceStanza, SessionContext sessionContext)
{
+        System.out.println("C: has become unavailable");
+    }
+
+    @SpecCompliant(spec = "RFC3921bis-04", section = "4.3.2")
+	private XMPPCoreStanza handleInboundPresenceProbe(PresenceStanza stanza, SessionContext
sessionContext, ResourceRegistry registry) {
 		Entity contact = stanza.getFrom();
 		Entity user = stanza.getTo();
 
@@ -133,8 +191,7 @@
 					"unsubscribed");
 		}
 
-		List<String> resources = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry().getAvailableResources(user);
+		List<String> resources = registry.getAvailableResources(user);
 		for (String resource : resources) {
 			Entity userResource = new EntityImpl(user, resource);
 			XMPPCoreStanza presence = null;
@@ -147,15 +204,13 @@
 	}
 
 	@SpecCompliant(spec = "RFC3921bis-04", section = "3.3.3")
-	private void handleInboundUnsubscription(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
+	private void handleInboundUnsubscription(PresenceStanza stanza, SessionContext sessionContext,
ResourceRegistry registry) {
 		Entity contact = stanza.getFrom();
 		Entity user = stanza.getTo();
 
 		// TODO: remove subscription from user to contact
 
-		List<String> resources = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry().getInterestedResources(user);
+		List<String> resources = registry.getInterestedResources(user);
 		for (String resource : resources) {
 			Entity userResource = new EntityImpl(user, resource);
 			// TODO: determine the right subscription: 'none' or 'to'
@@ -169,12 +224,8 @@
 	}
 
 	@SpecCompliant(spec = "RFC3921bis-04", section = "3.3.2")
-	private void handleOutboundUnsubscription(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
-		ServerRuntimeContext serverRuntimeContext = sessionContext
-				.getServerRuntimeContext();
-		ResourceRegistry registry = serverRuntimeContext.getResourceRegistry();
-
+	private void handleOutboundUnsubscription(PresenceStanza stanza,
+                                           SessionContext sessionContext, ResourceRegistry
registry) {
 		Entity user = stanza.getFrom();
 		Entity contact = stanza.getTo();
 
@@ -194,12 +245,10 @@
 	}
 
 	@SpecCompliant(spec = "RFC3921bis-04", section = "3.2.3")
-	private void handleInboundSubscriptionCancellation(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
+	private void handleInboundSubscriptionCancellation(PresenceStanza stanza,
+                                                    SessionContext sessionContext, ResourceRegistry
registry) {
 		// TODO: update roster for user
 		// TODO: if current subscription is either 'both' or
-		ResourceRegistry registry = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry();
 
 		Entity contact = stanza.getFrom();
 		Entity user = stanza.getTo();
@@ -217,16 +266,15 @@
 	}
 
 	@SpecCompliant(spec = "RFC3921bis-04", section = "3.2.2")
-	private void handleOutboundSubscriptionCancellation(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
+	private void handleOutboundSubscriptionCancellation(PresenceStanza stanza,
+                                                     SessionContext sessionContext, ResourceRegistry
registry) {
 		Entity user = stanza.getFrom();
 		Entity contact = stanza.getTo();
 
 		relayStanza(contact, stanza, sessionContext);
 
 		// send roster push to all of the user's interested resources
-		List<String> resources = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry().getInterestedResources(user);
+		List<String> resources = registry.getInterestedResources(user);
 		for (String resource : resources) {
 			Entity userResource = new EntityImpl(user, resource);
 			// TODO: determine the right subscription: 'to' or 'none'
@@ -240,11 +288,8 @@
 	}
 
 	@SpecCompliant(spec = "RFC3921bis-04", section = "3.1.5")
-	private void handleOutboundSubscriptionApproval(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
-		ResourceRegistry registry = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry();
-
+	private void handleOutboundSubscriptionApproval(PresenceStanza stanza,
+                                                 SessionContext sessionContext, ResourceRegistry
registry) {
 		Entity user = stanza.getFrom();
 		Entity contact = stanza.getTo();
 
@@ -276,8 +321,8 @@
 	}
 
 	@SpecCompliant(spec = "RFC3921bis-04", section = "3.1.6")
-	private Stanza handleInboundSubscriptionApproval(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
+	private Stanza handleInboundSubscriptionApproval(PresenceStanza stanza,
+                                                  SessionContext sessionContext, ResourceRegistry
registry) {
 
 		// TODO: check if contact is in users roster with
 		// subscription="from||none" && ask="subscribe"
@@ -285,12 +330,10 @@
 			Entity user = stanza.getTo();
 			Entity contact = stanza.getFrom();
 			// send roster push to all interested resources
-			List<String> resources = sessionContext.getServerRuntimeContext()
-					.getResourceRegistry().getInterestedResources(user);
+			List<String> resources = registry.getInterestedResources(user);
 			for (String resource : resources) {
 				Entity userResource = new EntityImpl(user, resource);
-				Stanza push = buildRosterPushStanza(userResource
-						.getFullQualifiedName(), sessionContext
+				Stanza push = buildRosterPushStanza(userResource.getFullQualifiedName(), sessionContext
 						.nextSequenceValue(), contact.getBareJID(), "to");
 				relayStanza(userResource, push, sessionContext);
 			}
@@ -302,11 +345,8 @@
 	}
 
 	@SpecCompliant(spec = "RFC3920bis-04", section = "3.1.3")
-	private Stanza handleInboundSubscriptionRequest(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
-		ResourceRegistry registry = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry();
-
+	private Stanza handleInboundSubscriptionRequest(PresenceStanza stanza,
+                                                 SessionContext sessionContext, ResourceRegistry
registry) {
 		Entity contact = stanza.getFrom();
 		Entity user = stanza.getTo();
 
@@ -346,10 +386,9 @@
 	}
 
 	@SpecCompliant(spec = "RFC3920bis-04", section = "3.1.2")
-	private void handleOutboundSubscriptionRequest(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
-		ServerRuntimeContext serverRuntimeContext = sessionContext
-				.getServerRuntimeContext();
+	private void handleOutboundSubscriptionRequest(PresenceStanza stanza,
+                                                SessionContext sessionContext, ResourceRegistry
registry) {
+		ServerRuntimeContext serverRuntimeContext = sessionContext.getServerRuntimeContext();
 		StanzaRelay stanzaRelay = serverRuntimeContext.getStanzaRelay();
 
 		// relay the stanza to the contact's server
@@ -363,8 +402,7 @@
 		Entity contact = stanza.getTo();
 
 		// send roster push to all of the user's interested resources
-		List<String> resources = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry().getInterestedResources(user);
+		List<String> resources = registry.getInterestedResources(user);
 		for (String resource : resources) {
 			Entity userResource = new EntityImpl(user, resource);
 			Stanza push = buildRosterPushStanza(userResource
@@ -380,65 +418,55 @@
 	}
 
 	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.2")
-	private void handleOutboundInitialPresence(XMPPCoreStanza stanza,
-			SessionContext sessionContext, Entity initiatingEntity) {
-		ResourceRegistry registry = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry();
-
-		List<String> resourceIDs = registry.getResourcesForSession(sessionContext);
-		Entity user;
-		if (resourceIDs.size() == 1) {
-			user = new EntityImpl(initiatingEntity, resourceIDs.get(0));
-		} else {
-			user = stanza.getFrom();
-			if (user == null) {
-				// return error stanza
-			}
-		}
-		registry.setResourceState(user.getResource(), ResourceState.AVAILABLE);
-		// send probes to all contacts of the current jid where
-		// 'subscription' is either 'to' or 'both'
-		// and jid is not blocking inbound presence notification
-		// TODO: retrieve list of contacts that match the criteria mentioned
-		// above
-		List<Entity> contacts = new ArrayList<Entity>();
-		for (Entity contact : contacts) {
-			Stanza probeStanza = buildPresenceStanza(user
-					.getFullQualifiedName(), contact.getBareJID(), null);
-			relayStanza(contact, probeStanza, sessionContext);
-		}
+	private void handleOutboundInitialPresence(PresenceStanza stanza,
+                                            SessionContext sessionContext, ResourceRegistry
registry, Entity initiatingEntity) {
+        String resourceID = registry.getFirstResourceForSession(sessionContext);
+        Entity user = (resourceID != null) ? new EntityImpl(initiatingEntity, resourceID)
: stanza.getFrom();
+        if (user == null) {
+            // return error stanza
+        }
+        registry.setResourceState(user.getResource(), ResourceState.AVAILABLE);
+
+        // send probes to all contacts of the current jid where
+        // 'subscription' is either 'to' or 'both'
+        // and jid is not blocking inbound presence notification
+        // TODO: retrieve list of contacts that match the criteria mentioned
+        // above
+        List<Entity> contacts1 = new ArrayList<Entity>();
+        List<Entity> contacts = contacts1;
+        for (Entity contact : contacts) {
+            Stanza probeStanza = buildPresenceStanza(user.getFullQualifiedName(), contact.getBareJID(),
null);
+            relayStanza(contact, probeStanza, sessionContext);
+        }
+
+        // broadcast initial presence from full JID to contacts
+        // in roster with 'subscription' either 'from' or 'both'
+        // and not user is blocking outbound presence notifications
+        // TODO: retrieve list of contacts that match the criteria mentioned
+        // above
+        contacts = new ArrayList<Entity>();
+        for (Entity contact : contacts) {
+            Stanza presenceStanza = buildPresenceStanza(user.getFullQualifiedName(), contact.getBareJID(),
null);
+            relayStanza(contact, presenceStanza, sessionContext);
+        }
+
+        // TODO: also broadcast presence notification to all resources of
+        // current entity.
+        List<String> resources = registry.getAvailableResources(user);
+        for (String resource : resources) {
+            Entity otherResource = new EntityImpl(user, resource);
+            Stanza presenceStanza = buildPresenceStanza(user.getFullQualifiedName(),
+                    otherResource.getFullQualifiedName(), null);
+            relayStanza(otherResource, presenceStanza, sessionContext);
+        }
 
-		// broadcast initial presence from full JID to contacts
-		// in roster with 'subscription' either 'from' or 'both'
-		// and not user is blocking outbound presence notifications
-		// TODO: retrieve list of contacts that match the criteria mentioned
-		// above
-		contacts = new ArrayList<Entity>();
-		for (Entity contact : contacts) {
-			Stanza presenceStanza = buildPresenceStanza(user
-					.getFullQualifiedName(), contact.getBareJID(), null);
-			relayStanza(contact, presenceStanza, sessionContext);
-		}
-
-		// TODO: also broadcast presence notification to all resources of
-		// current entity.
-		List<String> resources = registry.getAvailableResources(user);
-		for (String resource : resources) {
-			Entity otherResource = new EntityImpl(user, resource);
-			Stanza presenceStanza = buildPresenceStanza(user
-					.getFullQualifiedName(), otherResource
-					.getFullQualifiedName(), null);
-			relayStanza(otherResource, presenceStanza, sessionContext);
-		}
-
-	}
+    }
 
 	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.3")
-	private void handleInboundInitialPresence(XMPPCoreStanza stanza,
-			SessionContext sessionContext) {
+	private void handleInboundInitialPresence(PresenceStanza stanza,
+                                           SessionContext sessionContext, ResourceRegistry
registry) {
 		Entity user = stanza.getTo();
-		List<String> resources = sessionContext.getServerRuntimeContext()
-				.getResourceRegistry().getAvailableResources(user);
+		List<String> resources = registry.getAvailableResources(user);
 
 		for (String resource : resources) {
 			Entity userResource = new EntityImpl(user, resource);
@@ -446,7 +474,7 @@
 		}
 	}
 
-	private XMPPCoreStanza buildPresenceStanza(String from, String to,
+	private PresenceStanza buildPresenceStanza(String from, String to,
 			String type) {
 		StanzaBuilder builder = new StanzaBuilder("presence");
 		builder.addAttribute("from", from);
@@ -454,7 +482,7 @@
 		if (type != null) {
 			builder.addAttribute("type", type);
 		}
-		return XMPPCoreStanza.getWrapper(builder.getFinalStanza());
+		return (PresenceStanza) XMPPCoreStanza.getWrapper(builder.getFinalStanza());
 	}
 
 	private Stanza buildRosterPushStanza(String to, String id,
@@ -485,8 +513,7 @@
 	private void relayStanza(Entity receiver, Stanza stanza,
 			SessionContext sessionContext) {
 		try {
-			sessionContext.getServerRuntimeContext().getStanzaRelay().relay(
-					receiver, stanza);
+			sessionContext.getServerRuntimeContext().getStanzaRelay().relay(receiver, stanza);
 		} catch (DeliveryException e) {
 			e.printStackTrace();
 		}

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java?rev=653602&r1=653601&r2=653602&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
Mon May  5 14:02:53 2008
@@ -118,7 +118,13 @@
 		}
 	}
 
-	public List<String> getResourcesForSession(SessionContext sessionContext) {
+	public String getFirstResourceForSession(SessionContext sessionContext) {
+        List<String> list = getResourcesForSession(sessionContext);
+        if (list != null && list.size() > 0) return list.get(0);
+        return null;
+    }
+    
+    public List<String> getResourcesForSession(SessionContext sessionContext) {
 		if (sessionContext == null)
 			return null;
 
@@ -219,9 +225,9 @@
 	 * @return the {@link ResourceState}
 	 */
 	public ResourceState getResourceState(String resourceId) {
-		SessionData data = boundResources.get(resourceId);
-		if (data == null)
-			return null;
+        if (resourceId == null) return null;
+        SessionData data = boundResources.get(resourceId);
+		if (data == null) return null;
 		return data.state;
 	}
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanzaType.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanzaType.java?rev=653602&r1=653601&r2=653602&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanzaType.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanzaType.java Mon May
 5 14:02:53 2008
@@ -21,7 +21,6 @@
  */
 public enum PresenceStanzaType {
 
-    CHAT ("chat"),
     UNAVAILABLE("unavailable"),
     SUBSCRIBE("subscribe"),
     SUBSCRIBED("subscribed"),

Modified: labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java?rev=653602&r1=653601&r2=653602&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java (original)
+++ labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java Mon May  5 14:02:53
2008
@@ -23,6 +23,7 @@
 import org.jivesoftware.smack.XMPPConnection;
 import org.jivesoftware.smack.XMPPException;
 import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Presence;
 
 import java.util.Date;
 import java.util.Random;
@@ -33,7 +34,7 @@
     public static void main(String[] args) throws XMPPException {
 
         String me = args[0];
-        String to = args[1];
+        String to = args.length > 0 ? null : args[1];
         
         try {
             ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("localhost");
@@ -60,12 +61,17 @@
                 public void processMessage(Chat chat, Message message) { 
                     System.out.println("log received message: " + message.getBody()); } 
                  });
-            while (true) {
+            
+            connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available));
+            
+            while (to != null) {
                 chat.sendMessage("Hello " + to + " at " + new Date());
                 try { Thread.sleep((new Random().nextInt(9)+1)*1000 ); } catch (InterruptedException
e) { ; }
             }
 
-            //connection.disconnect(); 
+            try { Thread.sleep(120*1000 ); } catch (InterruptedException e) { ; }
+            
+            connection.disconnect(); 
         } catch (Throwable e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
         }



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


Mime
View raw message