📄 presencecontroller.java
字号:
package net.jxta.myjxta.presence;import net.jxta.myjxta.MyJXTA;import net.jxta.myjxta.View;import net.jxta.myjxta.ui.MyJXTAView;import net.jxta.myjxta.ui.SingleGroupNavigationPanel;import net.jxta.myjxta.util.Group;import net.jxta.myjxta.util.Peer;import net.jxta.pipe.PipeID;import net.jxta.protocol.PipeAdvertisement;import java.util.HashMap;import java.util.Iterator;import java.util.Vector;/** * right now this is only a helper package, is NOT the presence implementation you are looking for ;-) ! */public class PresenceController { private static final HashMap<Group, PeerStatus> groupStatus = new HashMap<Group, PeerStatus>(); private static final HashMap<Object, PresenceController> controllers = new HashMap<Object, PresenceController>(); private final Object m_communityKey; private Vector<PeerEntry> m_rows = new Vector<PeerEntry>(); public static PeerStatus defaultStatus = PeerStatus.getOnlineState("not set"); public static final PresenceController getController(String communityIdentifier) { PresenceController cont = controllers.get(communityIdentifier); if (cont == null) { cont = new PresenceController(communityIdentifier); controllers.put(cont.getCommunityKey(), cont); } return cont; } private Object getCommunityKey() { return m_communityKey; } private PresenceController(String key) { m_communityKey = key; } private synchronized Vector<PeerEntry> getAllContactsUnsorted() { return m_rows; } public synchronized Vector<PeerEntry> getAllContacts(){ return getAllContactsUnsorted(); } public static PeerEntry isNameKnown(Group p_group, String p_name, PipeID p_contactPipe) { for (Iterator<PeerEntry> iterator = getController(p_group.getId()).getAllContacts().iterator(); iterator.hasNext();) { PeerEntry peerEntry = iterator.next(); Peer peer = peerEntry.m_peer; if (peer.getName().equals(p_name)) { if (p_contactPipe == null || peer.getPipeAdvertisement().getID().equals(p_contactPipe)) { //no pipe id specified? --> use only the name, otherwise try to find the correct pipeid return peerEntry; } } } return null; } public static boolean updateLastSeen(Group group, String originatorName, PipeID originatorPipeID, PeerStatus senderState) { PeerEntry peerEntry = isNameKnown(group, originatorName, originatorPipeID); if (peerEntry != null) { peerEntry.updateLastSeen(senderState); return true; } else { return false; } } public static void pingAllNodesInGroup(Group group) { View view = MyJXTA.getTheInstance().getView(); if (view instanceof MyJXTAView) { SingleGroupNavigationPanel singleGroupPanel = ((MyJXTAView) view).getNavigationForGroup(group); if (singleGroupPanel != null) { singleGroupPanel.pingAllNodes(); } } } public static PeerStatus getOwnPeerState(Group group) { PeerStatus ownState = groupStatus.get(group); if (ownState == null) { ownState = defaultStatus; } return ownState; } public static String getOnlineStatusState(PipeAdvertisement requestor, Group group) { return getOwnPeerState(group).getState(); } public static PeerStatus setOwnPeerStatus(Group g, PeerStatus newStatus) { PeerStatus oldStatus = getOwnPeerState(g); if (g == null) { defaultStatus = newStatus; } else { groupStatus.put(g, newStatus); } return oldStatus; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -