本文整理汇总了Java中org.xmpp.packet.Presence.setFrom方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.setFrom方法的具体用法?Java Presence.setFrom怎么用?Java Presence.setFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Presence
的用法示例。
在下文中一共展示了Presence.setFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: route
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* 路由这个Presence包
*
* @param packet
*/
public void route(Presence packet) {
if (packet == null) {
throw new NullPointerException();
}
ClientSession session = sessionManager.getSession(packet.getFrom());
if (session == null || session.getStatus() != Session.STATUS_CONNECTED) {
handle(packet);
} else {
packet.setTo(session.getAddress());
packet.setFrom((JID) null);
packet.setError(PacketError.Condition.not_authorized);
session.process(packet);
}
}
示例2: sendStatusToAllAgents
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sends this agent's status to all other agents in the Workgroup.
*
* @param workgroup the workgroup whose agent will be notified
*/
private void sendStatusToAllAgents(Workgroup workgroup) {
for (AgentSession agentSession : workgroup.getAgentSessions()) {
// Only send presences to Agents that are available and had requested to
// receive other agents' information
if (agentSession.hasRequestedAgentInfo() && !agentSession.getJID().equals(address)) {
Presence statusPacket = presence.createCopy();
statusPacket.setFrom(address);
statusPacket.setTo(agentSession.getJID());
// Add the agent-status element
getAgentStatus(statusPacket, workgroup);
workgroup.send(statusPacket);
}
}
}
示例3: sendPresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sends the current presence to the session user.
*
* @param to JID to send presence updates to.
*/
public void sendPresence(JID to) {
// TODO: Should figure out best way to handle unknown here.
Presence p = new Presence();
p.setTo(to);
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (verboseStatus != null && verboseStatus.length() > 0) {
p.setStatus(verboseStatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
示例4: acceptSubscription
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void acceptSubscription(JID toJID, JID fromJID) throws PacketRejectedException {
if (getSubscriptionLevel().equals(LOCAL)) {
String toDomain = toJID.getDomain();
String fromDomain = fromJID.getDomain();
if (!toDomain.equals(serverName) || !fromDomain.equals(serverName)) {
return;
}
}
// Simulate that the target user has accepted the presence subscription request
Presence presence = new Presence();
presence.setType(Presence.Type.subscribed);
presence.setTo(fromJID);
presence.setFrom(toJID);
router.route(presence);
throw new PacketRejectedException();
}
示例5: onConnectionClose
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void onConnectionClose(Object handback) {
try {
ClientSession session = (ClientSession) handback;
try {
if ((session.getPresence().isAvailable() || !session
.wasAvailable())) {
// Send an unavailable presence to the user's subscribers
Presence presence = new Presence();
presence.setType(Presence.Type.unavailable);
presence.setFrom(session.getAddress());
// router.route(presence);
}
} finally {
removeSession(session);
}
} catch (Exception e) {
// Can't do anything about this problem...
log.error("Could not close socket", e);
}
}
示例6: onConnectionClose
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Handle a session that just closed.
*
* @param handback The session that just closed
*/
public void onConnectionClose(Object handback) {
try {
LocalClientSession session = (LocalClientSession) handback;
try {
if ((session.getPresence().isAvailable() || !session.wasAvailable()) &&
routingTable.hasClientRoute(session.getAddress())) {
// Send an unavailable presence to the user's subscribers
// Note: This gives us a chance to send an unavailable presence to the
// entities that the user sent directed presences
Presence presence = new Presence();
presence.setType(Presence.Type.unavailable);
presence.setFrom(session.getAddress());
router.route(presence);
}
}
finally {
// Remove the session
removeSession(session);
}
}
catch (Exception e) {
// Can't do anything about this problem...
Log.error(LocaleUtils.getLocalizedString("admin.error.close"), e);
}
}
示例7: rejectSubscription
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void rejectSubscription(JID toJID, JID fromJID) throws PacketRejectedException {
if (getSubscriptionLevel().equals(LOCAL)) {
String toDomain = toJID.getDomain();
String fromDomain = fromJID.getDomain();
if (toDomain.equals(serverName) && fromDomain.equals(serverName)) {
return;
}
}
// Simulate that the target user has rejected the presence subscription request
Presence presence = new Presence();
presence.setType(Presence.Type.unsubscribed);
// This is to get around an issue in Spark
// (http://www.igniterealtime.org/issues/browse/SPARK-300).
// Unfortunately, this is a bit of a hack and can easily be defeated
// if a user changes their resource when using Spark.
if (JiveGlobals.getBooleanProperty("plugin.subscription.sparkCheck", false)) {
String resource = fromJID.getResource();
if (resource != null && resource.equalsIgnoreCase("Spark")) {
presence.setType(Presence.Type.unsubscribed);
}
}
presence.setTo(fromJID);
presence.setFrom(toJID);
router.route(presence);
throw new PacketRejectedException();
}
示例8: contactAddedMe
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Someone added us to their contact list.
*/
public void contactAddedMe(MsnMessenger messenger, MsnContact friend) {
Log.debug("MSN: Contact added me: "+ friend.getFriendlyName());
final JID from = getSession().getTransport().convertIDToJID(friend.getEmail().toString());
final Presence p = new Presence();
p.setType(Presence.Type.subscribe);
p.setTo(getSession().getJID());
p.setFrom(from);
getSession().getTransport().sendPacket(p);
}
示例9: run
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Close detached client sessions that haven't seen activity in more than
* 30 minutes by default.
*/
@Override
public void run() {
int idleTime = getSessionDetachTime();
if (idleTime == -1) {
return;
}
final long deadline = System.currentTimeMillis() - idleTime;
for (LocalSession session : detachedSessions.values()) {
try {
if (session.getLastActiveDate().getTime() < deadline) {
removeDetached(session);
LocalClientSession clientSession = (LocalClientSession)session;
if (clientSession != null) {
try {
if ((clientSession.getPresence().isAvailable() || !clientSession.wasAvailable()) &&
routingTable.hasClientRoute(session.getAddress())) {
// Send an unavailable presence to the user's subscribers
// Note: This gives us a chance to send an unavailable presence to the
// entities that the user sent directed presences
Presence presence = new Presence();
presence.setType(Presence.Type.unavailable);
presence.setFrom(session.getAddress());
router.route(presence);
}
session.getStreamManager().onClose(router, serverAddress);
} finally {
// Remove the session
removeSession(clientSession);
}
}
}
}
catch (Throwable e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
示例10: contactRemovedMe
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Someone removed us from their contact list.
*/
public void contactRemovedMe(MsnMessenger messenger, MsnContact friend) {
Log.debug("MSN: Contact removed me: "+ friend.getFriendlyName());
Presence p = new Presence();
p.setType(Presence.Type.unsubscribe);
p.setTo(getSession().getJID());
p.setFrom(getSession().getTransport().convertIDToJID(friend.getEmail().toString()));
getSession().getTransport().sendPacket(p);
}
示例11: probePresences
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void probePresences(final PubSubService service) {
Set<JID> affiliates = new HashSet<JID>();
for (Node node : service.getNodes()) {
affiliates.addAll(node.getPresenceBasedSubscribers());
}
for (JID jid : affiliates) {
// Send probe presence
Presence subscription = new Presence(Presence.Type.probe);
subscription.setTo(jid);
subscription.setFrom(service.getAddress());
service.send(subscription);
}
}
示例12: setPresenceAndStatus
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Convenience routine to set both presence and verbose status at the same time.
*
* @param newpresence New presence to set to.
* @param newstatus New verbose status.
*/
public void setPresenceAndStatus(PresenceType newpresence, String newstatus) {
Log.debug("Updating status ["+newpresence+","+newstatus+"] for "+this);
if (newpresence == null) {
newpresence = PresenceType.unknown;
}
if (newstatus == null) {
newstatus = "";
}
if (newpresence.equals(PresenceType.unavailable)) {
newstatus = "";
}
if ((!presence.equals(newpresence) && newpresence != PresenceType.unknown) || !verboseStatus.equals(newstatus)) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, newpresence);
if (!newstatus.equals("")) {
p.setStatus(newstatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
presence = newpresence;
verboseStatus = newstatus;
lastActivityTimestamp = new Date().getTime();
lastActivityEvent = verboseStatus;
}
示例13: handleDeregister
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Processes an IQ-register request that is expressing the wish to
* deregister from a gateway.
*
* @param packet the IQ-register stanza.
*/
private void handleDeregister(final IQ packet) {
final IQ result = IQ.createResultIQ(packet);
if (packet.getChildElement().elements().size() != 1) {
Log.debug("Cannot process this stanza - exactly one"
+ " childelement of <remove> expected:" + packet.toXML());
final IQ error = IQ.createResultIQ(packet);
error.setError(Condition.bad_request);
parent.sendPacket(error);
return;
}
final JID from = packet.getFrom();
final JID to = packet.getTo();
// Tell the end user the transport went byebye.
final Presence unavailable = new Presence(Presence.Type.unavailable);
unavailable.setTo(from);
unavailable.setFrom(to);
this.parent.sendPacket(unavailable);
try {
deleteRegistration(from);
}
catch (UserNotFoundException e) {
Log.debug("Error cleaning up contact list of: " + from);
result.setError(Condition.registration_required);
}
parent.sendPacket(result);
}
示例14: contactAcceptedReceived
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* A contact has accepted our subscription request
*/
public void contactAcceptedReceived(SessionFriendAcceptedEvent event) {
final Set<String> groups = new HashSet<String>();
groups.add(event.getGroupName());
final YahooUser user = new YahooUser(event.getFrom());
// TODO clean up the next line. This implementation of constructor for YahooBuddy seems to be inappropriate here.
final YahooBuddy buddy = new YahooBuddy(getSession().getBuddyManager(), user, null, groups, null);
getSession().getBuddyManager().storeBuddy(buddy);
final Presence p = new Presence(Presence.Type.subscribed);
p.setTo(getSession().getJID());
p.setFrom(getSession().getTransport().convertIDToJID(event.getFrom()));
getSession().getTransport().sendPacket(p);
}
示例15: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* 处理出席数据包
*
* @param packet
*/
public void process(Packet packet) {
ClientSession session = sessionManager.getSession(packet.getFrom());
try {
Presence presence = (Presence) packet;
Presence.Type type = presence.getType();
if (type == null) { // null == available
if (session != null
&& session.getStatus() == Session.STATUS_CLOSED) {
log.warn("Rejected available presence: " + presence + " - "
+ session);
return;
}
if (session != null) {
session.setPresence(presence);
if (!session.isInitialized()) {
// initSession(session);
session.setInitialized(true);
}
List<Notification> list = notificationService
.findNotificationsByUsername(session.getUsername());
if (list != null && list.size() > 0) {
for (Notification notification : list) {
String apiKey = notification.getApiKey();
String title = notification.getTitle();
String message = notification.getMessage();
String uri = notification.getUri();
String imageUrl = notification.getImageUrl();
notificationManager.sendNotifcationToUser(apiKey,
session.getUsername(), title, message, uri,
imageUrl, false);
notificationService
.deleteNotification(notification);
}
}
}
} else if (Presence.Type.unavailable == type) {// 不可用的
if (session != null) {
session.setPresence(presence);
}
} else {
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(),
null, true));
presence.setTo(session.getAddress());
} else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.bad_request);
PacketDeliverer.deliver(presence);
}
} catch (Exception e) {
log.error("内部服务器错误. Triggered by packet: " + packet, e);
}
}