掲示板

how to get all user online

14年前 に Dariusz Sawicki によって更新されました。

how to get all user online

Regular Member 投稿: 165 参加年月日: 09/03/27 最新の投稿
Hi
I try develop portlet which show me which users is online.
I have list for all users but i don't know how i can check which of this users is online.

Thanks for help

Best Regards
Dariusz Sawicki
14年前 に Arun Kumar S によって更新されました。

RE: how to get all user online

Regular Member 投稿: 182 参加年月日: 08/06/23 最新の投稿
Dariusz Sawicki:
Hi
I try develop portlet which show me which users is online.
I have list for all users but i don't know how i can check which of this users is online.

Thanks for help

Best Regards
Dariusz Sawicki




Use this api com.liferay.portal.liveusers.LiveUsers to get online users.

HTH,
Arun
thumbnail
14年前 に Ahamed Sakir によって更新されました。

RE: how to get all user online

Regular Member 投稿: 129 参加年月日: 08/08/22 最新の投稿
Dariusz Sawicki ,

Just enable following properties in ur portlet-ext.properties

live.users.enabled=true
session.tracker.persistence.enabled=true
session.tracker.friendly.paths.enabled=true

then start the server.Go to control panel-->Monitoring--> U can able to see current viewing users full details.

(or)
If u want to see only name and photo write following code in ur jsp

<%@ page import="com.liferay.chat.service.StatusLocalServiceUtil" %>
List<Object[]> buddies = null;
long buddiesModifiedDate = System.currentTimeMillis() - Time.MINUTE;
buddies = StatusLocalServiceUtil.getAllStatuses(themeDisplay.getUserId(), buddiesModifiedDate, 0, SearchContainer.DEFAULT_DELTA);
out.println("Online visiting Users ="+ buddies.size());

From the List buddies u can get the name ,etc..
For reference check Chat portlet code.

Regards
Sakir
14年前 に Dariusz Sawicki によって更新されました。

RE: how to get all user online

Regular Member 投稿: 165 参加年月日: 09/03/27 最新の投稿
Thanks for replay
I try this put in my portlet :


&lt;%@ page import="com.liferay.chat.service.StatusLocalServiceUtil" %&gt;
List<object[]> buddies = null;
long buddiesModifiedDate = System.currentTimeMillis() - Time.MINUTE;
buddies = StatusLocalServiceUtil.getAllStatuses(themeDisplay.getUserId(), buddiesModifiedDate, 0, SearchContainer.DEFAULT_DELTA);
out.println("Online visiting Users ="+ buddies.size())

</object[]>


but i have this ERROR :



14:12:41,062 ERROR [PortletBeanLocatorUtil:49] BeanLocator is null
14:12:41,078 ERROR [[jsp]:711] Servlet.service() for servlet jsp threw exception
com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set
	at com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(PortletBeanLocatorUtil.java:51)
	at com.liferay.chat.service.StatusLocalServiceUtil.getService(StatusLocalServiceUtil.java:128)
	at com.liferay.chat.service.StatusLocalServiceUtil.getStatusesCount(StatusLocalServiceUtil.java:81)
	at org.apache.jsp.WEB_002dINF.jsp.Count_005fUser_005fActiv_005fview_jsp._jspService(Count_005fUser_005fActiv_005fview_jsp.java:226)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)




How i can fixed it?

Best Regards

Dariusz
14年前 に Dariusz Sawicki によって更新されました。

RE: how to get all user online

Regular Member 投稿: 165 参加年月日: 09/03/27 最新の投稿
Hi again
a try this to by import portal-impl.jar to my project (i can use it only in class :/) :



ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
 themeDisplay.getCompanyId();
Map<string, usertracker> sessionUsers = LiveUsers.getSessionUsers(themeDisplay.getCompanyId());

		int total = sessionUsers.size();

</string,>


but i get always total = 0

Thanks for help

Dariusz
13年前 に Kostas Hav によって更新されました。

RE: how to get all user online

New Member 投稿: 3 参加年月日: 10/05/13 最新の投稿
Dariusz Sawicki:
Thanks for replay
I try this put in my portlet :


&lt;%@ page import="com.liferay.chat.service.StatusLocalServiceUtil" %&gt;
List<object[]> buddies = null;
long buddiesModifiedDate = System.currentTimeMillis() - Time.MINUTE;
buddies = StatusLocalServiceUtil.getAllStatuses(themeDisplay.getUserId(), buddiesModifiedDate, 0, SearchContainer.DEFAULT_DELTA);
out.println("Online visiting Users ="+ buddies.size())

</object[]>


but i have this ERROR :



14:12:41,062 ERROR [PortletBeanLocatorUtil:49] BeanLocator is null
14:12:41,078 ERROR [[jsp]:711] Servlet.service() for servlet jsp threw exception
com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set
	at com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(PortletBeanLocatorUtil.java:51)
	at com.liferay.chat.service.StatusLocalServiceUtil.getService(StatusLocalServiceUtil.java:128)
	at com.liferay.chat.service.StatusLocalServiceUtil.getStatusesCount(StatusLocalServiceUtil.java:81)
	at org.apache.jsp.WEB_002dINF.jsp.Count_005fUser_005fActiv_005fview_jsp._jspService(Count_005fUser_005fActiv_005fview_jsp.java:226)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)




How i can fixed it?

Best Regards

Dariusz


Is anyone solve this problem??
13年前 に Ash J によって更新されました。

RE: how to get all user online

Junior Member 投稿: 83 参加年月日: 11/03/22 最新の投稿
Hi,

Could you please let me know how did you managed to get all the users?

I can't find a webservice that returns all the users in Liferay.

Thanks,
ash
13年前 に Ash J によって更新されました。

RE: how to get all user online

Junior Member 投稿: 83 参加年月日: 11/03/22 最新の投稿
ah... figured it out...

com.liferay.portal.service.UserLocalServiceUtil.getUser(int start, int end);

cheers,
ash
thumbnail
11年前 に Florencia Hernández によって更新されました。

RE: how to get all user online

Regular Member 投稿: 146 参加年月日: 12/03/27 最新の投稿
Well, that only gets all the users, not the ones logged in.

Did anyone solve this?
thumbnail
10年前 に Akash B Gajjar によって更新されました。

RE: how to get all user online

New Member 投稿: 5 参加年月日: 10/05/16 最新の投稿
Hi All,

To enable tracking of logged in users, first we have enable flag in portal-ext.properties as follows.

live.users.enabled=true

Now, if we want to get those tracked users in portlet, I am using reflection to grab the users.

Class<?> liveUsers = PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portal.liveusers.LiveUsers");
System.out.println(liveUsers);
Method getSessionUsers = liveUsers.getDeclaredMethod("getSessionUsers", long.class);
Object map = getSessionUsers.invoke(null, 10154);
System.out.println(map + " ---->");

I am not using any ext plugin to make above code work. It's a pure combination of PortalClassLoader and reflection.

Hope above solution helps.

Thx.
Akash Gajjar
9年前 に fouad fouad によって更新されました。

RE: how to get all user online

Junior Member 投稿: 28 参加年月日: 14/08/08 最新の投稿
Ash J:
ah... figured it out...

com.liferay.portal.service.UserLocalServiceUtil.getUser(int start, int end);

cheers,
ash



hello Ash
im new to liferay, and i want to have a portlet that gets the total all time users and the online users.
can you guide me to see how and where i should use "com.liferay.portal.service.UserLocalServiceUtil.getUser(int start, int end);"


thank you
thumbnail
9年前 に Miroslav Ligas によって更新されました。

RE: how to get all user online

Regular Member 投稿: 152 参加年月日: 14/07/29 最新の投稿
If you wont to count all users in DB for a company. Use

com.liferay.portal.service.UserLocalServiceUtil.getCompanyUsersCount(companyId)


you can get the companyID form ThemeDisplay or CompanyThreadLocal

The number of the online user may be observed by enabling live.users.enabled=true but it will have performance impact. If you want to count the online users in a custom portlet I would probably try to implement a session listener and count the open sessions. Any user guest or logged in has a session so the numbers should be OK.
9年前 に fouad fouad によって更新されました。

RE: how to get all user online

Junior Member 投稿: 28 参加年月日: 14/08/08 最新の投稿
Miroslav Ligas:
If you wont to count all users in DB for a company. Use

com.liferay.portal.service.UserLocalServiceUtil.getCompanyUsersCount(companyId)


you can get the companyID form ThemeDisplay or CompanyThreadLocal

The number of the online user may be observed by enabling live.users.enabled=true but it will have performance impact. If you want to count the online users in a custom portlet I would probably try to implement a session listener and count the open sessions. Any user guest or logged in has a session so the numbers should be OK.



good morning Miroslav.
thank you for your reply, i have enabled live.users.enabled=true, but i dont know how to continue from there.
please can you guide me .
thumbnail
9年前 に Miroslav Ligas によって更新されました。

RE: how to get all user online

Regular Member 投稿: 152 参加年月日: 14/07/29 最新の投稿
If you enable the option you can see the current sessions in Control Panel > Users >Monitoring. I tested it and it does not show the guest users so it's probably not what you need. It also is based on LiveUsers.java which is a internal class and you would need the portal class invoker to make it work (there was a recent blog post about how to use PortalClassInvoker)

I think the easiest way for you would be to listen to the session creation on the server and count them.
http://www.mkyong.com/servlet/a-simple-httpsessionlistener-example-active-sessions-counter/. On create you increment the counter on destroy you decrease the counter. Important is to add the listener to Liferay not to your portlet. You want to count the number of session Liferay is creating.
9年前 に fouad fouad によって更新されました。

RE: how to get all user online

Junior Member 投稿: 28 参加年月日: 14/08/08 最新の投稿
Miroslav Ligas:
If you enable the option you can see the current sessions in Control Panel > Users >Monitoring. I tested it and it does not show the guest users so it's probably not what you need. It also is based on LiveUsers.java which is a internal class and you would need the portal class invoker to make it work (there was a recent blog post about how to use PortalClassInvoker)

I think the easiest way for you would be to listen to the session creation on the server and count them.
http://www.mkyong.com/servlet/a-simple-httpsessionlistener-example-active-sessions-counter/. On create you increment the counter on destroy you decrease the counter. Important is to add the listener to Liferay not to your portlet. You want to count the number of session Liferay is creating.


hello again Miroslav
first of all, thank you for helping me.

i read the post that u recommended, i understand the code and the concept but iam not able to make it run.
excuse me if my sentence is not right, but as iam searching the web on how to add a listener class to liferay i read that i need to create a hook , service builder, and ....... why do i need hooks?

i am v new to liferay, please can you give me the steps on how to accomplish this.

again thank you for your patience
thumbnail
9年前 に Zsolt - Jácint Balogh によって更新されました。

RE: how to get all user online

Junior Member 投稿: 91 参加年月日: 13/10/09 最新の投稿
sawi _:
Hi
I try develop portlet which show me which users is online.
I have list for all users but i don't know how i can check which of this users is online.

Thanks for help

Best Regards
Dariusz Sawicki



Hi all, We solved this problem...
We tried to use some services from the cheat portlet and a lot of thing but did not worked.

I suggest you to create a post login hook. Save the users and when the session destroys delete them from the list.
This is a working solution we use in two web sites.

You have to add three class to your portlet:
A model where you can store the logged in users:


private static Set<long> users = new HashSet<long>();

    public static void addUser(long userId) {
        users.add(userId);
    }

    public static void clearUsers() {
        users.clear();
    }

    public static void removeUser(long userId) {
        users.remove(userId);
    }

    public static int countUsers() {
        return users.size();
    }

    public static boolean isLogged(long userId) {
        return users.contains(userId);
    }
</long></long>


The port login action

public class LoginPostAction extends Action {

    @Override
    public void run(HttpServletRequest request, HttpServletResponse response) {
        long userId = PortalUtil.getUserId(request);
        LiveUsers.addUser(userId);
    }

}



The session destroy action:


import com.liferay.portal.kernel.events.SessionAction;
import com.liferay.portal.kernel.util.WebKeys;

import javax.servlet.http.HttpSession;

/**
 * @author Bruno Farache
 */
public class SessionDestroyAction extends SessionAction {

    @Override
    public void run(HttpSession session) {
        Long userId = (Long) session.getAttribute(WebKeys.USER_ID);
        LiveUsers.removeUser(userId);
    }

}



After you have this classes you have to add this two class to the portal.properties
login.events.post=xxx.LoginPostAction
servlet.session.destroy.events=xxx.SessionDestroyAction

You can do this with a hook or you can add a liferay-hook.xml to your web-inf folder with content:

<!--?xml version="1.0"?-->


<hook>
    <portal-properties>portal.properties</portal-properties>
</hook>

and add a portal.properties file to the resources folder.

For creating post login action see:
https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/performing-a-custom-acti-4

Do the same thing with session destroy event and you can find your logged in users in the users set.

@Edit: You have to add this classes into your portlet to see the users set. You can find information about that here: http://vkbardia.blogspot.ro/2012/05/create-hook-inside-portlet-liferay.html

I hope this helped,
Regards,
Zsolt
thumbnail
9年前 に Miroslav Ligas によって更新されました。

RE: how to get all user online

Regular Member 投稿: 152 参加年月日: 14/07/29 最新の投稿
Yep that's a good solution. But it will count only logged in users. If that's what you need, go for it. I thought that you needed also guest users but that was a different thread emoticon

You can monitor also the session in the hook you need to create the SessionCreate and SessionDestroy action and refer to them in the portal.properties file
servlet.session.create.events
servlet.session.destroy.events

Thanks Zsolt for the detailed steps.
8年前 に Le Linh によって更新されました。

RE: how to get all user online

New Member 投稿: 1 参加年月日: 16/01/12 最新の投稿
Yeah, that's a good solution.
Thanks you so murch!