You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nuvem-commits@incubator.apache.org by jo...@apache.org on 2011/05/02 23:06:39 UTC
svn commit: r1098841 - in
/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence:
./ Presence.java PresenceAttributes.java PresenceBuilder.java
PresenceListener.java PresenceManager.java
Author: johnp
Date: Mon May 2 23:06:39 2011
New Revision: 1098841
URL: http://svn.apache.org/viewvc?rev=1098841&view=rev
Log:
Adding the initial XMPP presence management code, this code will be revised/refactored and appropriate test cases and sample code for store app will be added as the next step
Added:
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/Presence.java
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceAttributes.java
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceBuilder.java
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceListener.java
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceManager.java
Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/Presence.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/Presence.java?rev=1098841&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/Presence.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/Presence.java Mon May 2 23:06:39 2011
@@ -0,0 +1,62 @@
+/*
+ * 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.nuvem.cloud.xmpp.api.presence;
+
+/**
+ * Represents the presence XMPP stanza, it could be one of the below type of
+ * presence stanza
+ * <ul>
+ * <li>presence broad cast by a JID which conveys its current presence state
+ * <li>initial presence state of a JID when it logs into the XMPP server.
+ * </ul>
+ *
+ */
+public final class Presence extends PresenceAttributes {
+
+ /**
+ * Constructor which takes a builder as parameter to maintain immutability.
+ *
+ */
+ public Presence(PresenceBuilder builder) {
+ this.from = builder.from();
+ this.status = builder.status();
+ this.type = builder.type();
+ this.show = builder.show();
+ this.to = builder.to();
+ this.stanza = builder.stanza();
+ }
+
+ /**
+ * Represents the substanza of the presence stanza.
+ *
+ */
+ public enum Show {
+ AVAILABLE, CHAT, AWAY, DND, XA, NONE;
+ }
+
+ /**
+ * Represents the type of the presence stanza.
+ *
+ */
+ public enum Type {
+ AVAILABLE, PROBE, UNAVAILABLE, SUBSCRIBED, SUBSCRIBE, UNSUBSCRIBE, UNSUBSCRIBED, ERROR;
+ }
+}
Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceAttributes.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceAttributes.java?rev=1098841&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceAttributes.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceAttributes.java Mon May 2 23:06:39 2011
@@ -0,0 +1,101 @@
+/*
+ * 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.nuvem.cloud.xmpp.api.presence;
+
+import org.apache.nuvem.cloud.xmpp.api.JID;
+
+/**
+ * Serves as a super class to hold all the attributes related to the presence
+ * stanza to avoid duplicate attributes and methods in both the {@link Presence}
+ * and {@link PresenceBuilder} classes.
+ *
+ */
+public class PresenceAttributes {
+
+ /**
+ * The sender of a presence.
+ */
+ protected JID from;
+
+ /**
+ * The recipient of the presence.
+ */
+ protected JID to;
+
+ /**
+ * The stanza of the presence message.
+ */
+ protected String stanza;
+
+ /**
+ * The additional status string sent by an entity.
+ */
+ protected String status;
+
+ /**
+ * Additional availability status along with the {@link #type}} value
+ */
+ protected Presence.Show show;
+
+ /**
+ * Represents the type of the presence stanza which could be
+ * <ul>
+ * <li>unavailable -- Signals that the entity is no longer available for communication.
+ * <li>subscribe -- The sender wishes to subscribe to the recipient's presence.
+ * <li>subscribed -- The sender has allowed the recipient to receive their presence.
+ * <li>unsubscribe -- The sender is unsubscribing from another entity's presence.
+ * <li>unsubscribed -- The subscription request has been denied or a previously-granted subscription has been cancelled.
+ * <li>probe -- A request for an entity's current presence; SHOULD be generated only by a server on behalf of a user.
+ * <li>error -- An error has occurred regarding processing or delivery of a previously-sent presence stanza.
+ * </ul>
+ */
+ protected Presence.Type type;
+
+ /**
+ * The priority of the presence message.
+ */
+ protected int priority;
+
+ public final Presence.Type type() {
+ return type;
+ }
+
+ public final Presence.Show show() {
+ return show;
+ }
+
+ public final JID from() {
+ return from;
+ }
+
+ public final JID to() {
+ return to;
+ }
+
+ public final String stanza() {
+ return stanza;
+ }
+
+ public final String status() {
+ return status;
+ }
+
+}
Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceBuilder.java?rev=1098841&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceBuilder.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceBuilder.java Mon May 2 23:06:39 2011
@@ -0,0 +1,108 @@
+/*
+ * 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.nuvem.cloud.xmpp.api.presence;
+
+import org.apache.nuvem.cloud.xmpp.api.JID;
+
+/**
+ * Builds the presence object.
+ *
+ */
+public final class PresenceBuilder extends PresenceAttributes {
+
+ /**
+ * Initializes the JID for recipient.
+ *
+ * @param jid
+ * the JID for the recipient.
+ * @return the message builder.
+ */
+ public PresenceBuilder toRecipient(String jid) {
+ this.to = new JID(jid);
+ return this;
+ }
+
+ /**
+ * The sender for a message.
+ *
+ * @param jid
+ * the jid of the sender.
+ * @return the message builder.
+ */
+ public PresenceBuilder from(String jid) {
+ this.from = new JID(jid);
+ return this;
+ }
+
+ /**
+ * Initialises the content for sending to the recipient.
+ *
+ * @param content
+ * the actual content.
+ * @return the message builder.
+ */
+ public PresenceBuilder withStanza(String stanza) {
+ this.stanza = stanza;
+ return this;
+ }
+
+ public PresenceBuilder withStatus(String status) {
+ this.status = status;
+ return this;
+ }
+
+ public PresenceBuilder withShow(Presence.Show show) {
+ this.show = show;
+ return this;
+ }
+
+ public PresenceBuilder withType(Presence.Type type) {
+ this.type = type;
+ return this;
+ }
+
+ public PresenceBuilder from(JID jid) {
+ this.from = jid;
+ return this;
+ }
+
+ public PresenceBuilder to(JID jid) {
+ this.to = jid;
+ return this;
+ }
+
+ /**
+ * Builds the Presence object by using all the previously passed attributes
+ * through various methods like.
+ * <ul>
+ * <li/>{@link #containing(Object)}
+ * <li/>{@link #toRecipient(String)}
+ * <li/>{@link #withShow(String)}
+ * <li/>{@link #withStanza(String)}
+ * <li/>{@link #withStatus(String)}
+ * <li/>{@link #withType(String)}
+ *
+ * @return
+ */
+ public Presence build() {
+ return new Presence(this);
+ }
+}
Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceListener.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceListener.java?rev=1098841&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceListener.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceListener.java Mon May 2 23:06:39 2011
@@ -0,0 +1,27 @@
+/*
+ * 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.nuvem.cloud.xmpp.api.presence;
+
+public interface PresenceListener {
+
+ void listen(Presence presence);
+
+}
Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceManager.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceManager.java?rev=1098841&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceManager.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/presence/PresenceManager.java Mon May 2 23:06:39 2011
@@ -0,0 +1,36 @@
+/*
+ * 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.nuvem.cloud.xmpp.api.presence;
+
+import java.util.List;
+
+/**
+ * Manages Presence inboud and outboud stanzas, Each cloud platform will have
+ * its own implementation of the PresenceManager.
+ *
+ */
+public interface PresenceManager {
+
+ void registerListener(PresenceListener listener);
+
+ List<PresenceListener> listeners();
+
+}