本文整理汇总了Java中org.jivesoftware.openfire.session.ClientSession类的典型用法代码示例。如果您正苦于以下问题:Java ClientSession类的具体用法?Java ClientSession怎么用?Java ClientSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientSession类属于org.jivesoftware.openfire.session包,在下文中一共展示了ClientSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sessionDestroyed
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
public void sessionDestroyed(Session session)
{
Log.debug("OfMeet Plugin - sessionDestroyed "+ session.getAddress().toString() + "\n" + ((ClientSession) session).getPresence().toXML());
boolean skypeAvailable = XMPPServer.getInstance().getPluginManager().getPlugin("ofskype") != null;
if (OfMeetAzure.skypeids.containsKey(session.getAddress().getNode()))
{
String sipuri = OfMeetAzure.skypeids.remove(session.getAddress().getNode());
IQ iq = new IQ(IQ.Type.set);
iq.setFrom(session.getAddress());
iq.setTo(XMPPServer.getInstance().getServerInfo().getXMPPDomain());
Element child = iq.setChildElement("request", "http://igniterealtime.org/protocol/ofskype");
child.setText("{'action':'stop_skype_user', 'sipuri':'" + sipuri + "'}");
XMPPServer.getInstance().getIQRouter().route(iq);
Log.info("OfMeet Plugin - closing skype session " + sipuri);
}
}
示例2: isOnline
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
@Override
public boolean isOnline(JID user) {
long start = System.nanoTime();
SessionManager sessionManager = getSessionManager();
Collection<ClientSession> sessions = sessionManager.getSessions(user.getNode());
boolean activeSession = false;
for (ClientSession clientSession : sessions) {
JID clientSessionAddress = clientSession.getAddress();
//compare the node and the resource
if (clientSessionAddress.getNode().equals(user.getNode()) && clientSessionAddress.getResource().equals(user.getResource())) {
//if (clientSession.getAddress().equals(user)) {
if (clientSession.isInitialized()) {
activeSession = true;
break;
}
}
}
long end = System.nanoTime();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format ("For user:%s presence value:%s", user, activeSession));
long delta = end - start;
LOGGER.debug("Presence was checked in:" + (delta/1000) + " ms");
}
return activeSession;
}
示例3: logout
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
/**
* Disconnect an XMPP session of a user identified by an oauth token.
* @param headers
* @return
*/
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("logout")
public Response logout(@Context HttpHeaders headers) {
TokenInfo tokenInfo = RestUtils.getAuthTokenInfo(headers);
if (tokenInfo == null) {
return RestUtils.getUnauthJAXRSResp();
}
JID from = RestUtils.createJID(tokenInfo);
XMPPServer xmppSrv = XMPPServer.getInstance();
SessionManager sessionMgr = xmppSrv.getSessionManager();
ClientSession session = sessionMgr.getSession(from);
if (session == null) {
ErrorResponse response = new ErrorResponse(ErrorCode.USER_NOT_LOGIN,
String.format("Session is not found: %s [%s]", from, tokenInfo.getUserName()));
return RestUtils.getJAXRSResp(Response.Status.GONE, response);
}
// Terminate the session now.
session.close();
return RestUtils.getOKJAXRSResp();
}
示例4: execute
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
@Override
public void execute(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel(getLabel());
field.setVariable("onlineusersnum");
// Make sure that we are only counting based on bareJIDs and not fullJIDs
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
Set<String> users = new HashSet<>(sessions.size());
for (ClientSession session : sessions) {
users.add(session.getAddress().toBareJID());
}
field.addValue(users.size());
command.add(form.getElement());
}
示例5: destroy
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
@Override
public void destroy()
{
// terminate any active websocket sessions
SessionManager sm = XMPPServer.getInstance().getSessionManager();
for (ClientSession session : sm.getSessions()) {
if (session instanceof LocalSession) {
Object ws = ((LocalSession) session).getSessionData("ws");
if (ws != null && (Boolean) ws) {
session.close();
}
}
}
super.destroy();
}
示例6: getPresence
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
@Override
public Presence getPresence(User user) {
if (user == null) {
return null;
}
Presence presence = null;
for (ClientSession session : sessionManager.getSessions(user.getUsername())) {
if (presence == null) {
presence = session.getPresence();
}
else {
// Get the ordinals of the presences to compare. If no ordinal is available then
// assume a value of -1
int o1 = presence.getShow() != null ? presence.getShow().ordinal() : -1;
int o2 = session.getPresence().getShow() != null ?
session.getPresence().getShow().ordinal() : -1;
// Compare the presences' show ordinals
if (o1 > o2) {
presence = session.getPresence();
}
}
}
return presence;
}
示例7: run
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
public void run() {
ClientSession session = ((ClientSession) getSession());
PrivacyList list = null;
// Get the privacy list to set
if (listName != null) {
try {
String username = session.getUsername();
list = PrivacyListManager.getInstance().getPrivacyList(username, listName);
} catch (UserNotFoundException e) {
// Should never happen
}
}
// Set the privacy list to the session
if (activeList) {
session.setActiveList(list);
}
else {
session.setDefaultList(list);
}
}
示例8: setActiveList
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
/**
* User has specified a new active list that should be used for the current session.
*
* @param packet IQ packet setting new active list for the current session.
* @param from sender of the IQ packet.
* @param listName name of the new active list for the current session.
* @return acknowledge of success.
*/
private IQ setActiveList(IQ packet, JID from, String listName) {
IQ result = IQ.createResultIQ(packet);
Element childElement = packet.getChildElement().createCopy();
result.setChildElement(childElement);
// Get the list
PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
if (list != null) {
// Get the user session
ClientSession session = sessionManager.getSession(from);
if (session != null) {
// Set the new active list for this session
session.setActiveList(list);
}
}
else {
// List not found
result.setError(PacketError.Condition.item_not_found);
}
return result;
}
示例9: execute
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
@Override
public void execute(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.result);
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setLabel(getLabel());
field.setVariable("activeusersnum");
// Make sure that we are only counting based on bareJIDs and not fullJIDs
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
Set<String> users = new HashSet<String>(sessions.size());
for (ClientSession session : sessions) {
if (session.getPresence().isAvailable()) {
users.add(session.getAddress().toBareJID());
}
}
field.addValue(users.size());
command.add(form.getElement());
}
示例10: declineDefaultList
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
/**
* User has specified that there is no default list that should be used for this user.
*
* @param packet IQ packet declining default list for all sessions.
* @param from sender of the IQ packet.
* @return acknowledge of success.
*/
private IQ declineDefaultList(IQ packet, JID from) {
IQ result = IQ.createResultIQ(packet);
Element childElement = packet.getChildElement().createCopy();
result.setChildElement(childElement);
if (sessionManager.getSessionCount(from.getNode()) > 1) {
// Current default list is being used by more than one session
result.setError(PacketError.Condition.conflict);
}
else {
// Get the user session
ClientSession session = sessionManager.getSession(from);
// Check if a default list was already defined
if (session.getDefaultList() != null) {
// Set the existing default list as non-default
session.getDefaultList().setDefaultList(false);
// Update the database with the new list state
provider.updatePrivacyList(from.getNode(), session.getDefaultList());
session.setDefaultList(null);
}
}
return result;
}
示例11: findUser
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
private JID findUser(String username)
{
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
JID foundUser = null;
for (ClientSession session : sessions)
{
try{
String userId = session.getAddress().getNode();
if (username.equals(userId))
{
Log.info("Incoming SIP, findUser " + session.getAddress());
foundUser = session.getAddress();
break;
}
} catch (Exception e) { }
}
return foundUser;
}
示例12: broadcastPresenceOfOtherResource
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
/**
* Sends the presences of other connected resources to the resource that just connected.
*
* @param session the newly created session.
*/
private void broadcastPresenceOfOtherResource(LocalClientSession session) {
if (!SessionManager.isOtherResourcePresenceEnabled()) {
return;
}
Presence presence;
// Get list of sessions of the same user
JID searchJID = new JID(session.getAddress().getNode(), session.getAddress().getDomain(), null);
List<JID> addresses = routingTable.getRoutes(searchJID, null);
for (JID address : addresses) {
if (address.equals(session.getAddress())) {
continue;
}
// Send the presence of an existing session to the session that has just changed
// the presence
ClientSession userSession = routingTable.getClientRoute(address);
presence = userSession.getPresence().createCopy();
presence.setTo(session.getAddress());
session.process(presence);
}
}
示例13: sessionDisconnected
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
/**
* Should be called when a session has been disconnected.
*
* This can be anything from a standard logout to a forced disconnect from the server.
*
* @param errorMessage Error message to send, or null if no message. (only sent on full disconnect)
*/
public void sessionDisconnected(String errorMessage) {
reconnectionAttempts++;
if (getRegistrationPacket() != null || !JiveGlobals.getBooleanProperty("plugin.gateway."+getTransport().getType()+"reconnect", true) || (reconnectionAttempts > JiveGlobals.getIntProperty("plugin.gateway."+getTransport().getType()+"reconnectattempts", 3))) {
sessionDisconnectedNoReconnect(errorMessage);
}
else {
cleanUp();
Log.debug("Session "+getJID()+" disconnected from "+getTransport().getJID()+". Reconnecting... (attempt "+reconnectionAttempts+")");
setLoginStatus(TransportLoginStatus.RECONNECTING);
ClientSession session = XMPPServer.getInstance().getSessionManager().getSession(getJIDWithHighestPriority());
if (session != null) {
logIn(getTransport().getPresenceType(session.getPresence()), null);
}
else {
sessionDisconnectedNoReconnect(errorMessage);
}
}
}
示例14: start
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
/**
* Handles startup of the transport.
*/
public void start() {
RosterEventDispatcher.addListener(this);
UserEventDispatcher.addListener(this);
SessionEventDispatcher.addListener(this);
VCardEventDispatcher.addListener(this);
InterceptorManager.getInstance().addInterceptor(this);
if (!JiveGlobals.getBooleanProperty("plugin.gateway.tweak.noprobeonstart", false)) {
// Probe all registered users [if they are logged in] to auto-log them in
// TODO: Do we need to account for local vs other node sessions?
for (ClientSession session : SessionManager.getInstance().getSessions()) {
try {
JID jid = XMPPServer.getInstance().createJID(session.getUsername(), null);
if (RegistrationManager.getInstance().isRegistered(jid, getType())) {
Presence p = new Presence(Presence.Type.probe);
p.setFrom(this.getJID());
p.setTo(jid);
sendPacket(p);
}
}
catch (UserNotFoundException e) {
// Not a valid user for the gateway then
}
}
}
}
示例15: findUser
import org.jivesoftware.openfire.session.ClientSession; //导入依赖的package包/类
private JID findUser(String username)
{
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions();
JID foundUser = null;
for (ClientSession session : sessions)
{
try{
String userId = session.getAddress().getNode();
if (username.equals(userId))
{
Log.info("Incoming SIP, findUser " + session.getAddress());
foundUser = session.getAddress();
break;
}
} catch (Exception e) { }
}
return foundUser;
}