[richfaces-issues] [JBoss JIRA] (RF-12219) Push: Test that messages do not become stale in a queue

Milo van der Zee (JIRA) jira-events at lists.jboss.org
Thu May 24 09:11:20 EDT 2012


    [ https://issues.jboss.org/browse/RF-12219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12695541#comment-12695541 ] 

Milo van der Zee edited comment on RF-12219 at 5/24/12 9:10 AM:
----------------------------------------------------------------

I changed PushResource.java a little and at first glance it seems to do the trick. I realize that my fix/workaround limits the functionality in that all push clients must have different topic names on one page. Don't know if that was the case before my changes. As far as I can see you could use multiple push components listening to the same topic on one page. Not anymore...

{code:title="PushResource.java"}
	public void encode(FacesContext facesContext) throws IOException {
		ExternalContext externalContext = facesContext.getExternalContext();

		PushContextFactory pushContextFactory = ServiceTracker.getService(PushContextFactory.class);

		// resource plugin stub
		if (pushContextFactory == null) {
			return;
		}

		PushContext pushContext = pushContextFactory.getPushContext();

		String forgetPushSessionId = externalContext.getRequestParameterMap().get(FORGET_PUSH_SESSION_ID_PARAM);
		if (forgetPushSessionId != null) {
			Session oldSession = pushContext.getSessionManager().getPushSession(forgetPushSessionId);
			if (oldSession != null) {
				oldSession.invalidate();
			}
		}

		// Session session = pushContext.getSessionFactory().createSession(UUID.randomUUID().toString());
		HttpSession httpSession = (HttpSession)externalContext.getSession(false);
		String sessionId = httpSession.getId();
		Session session = pushContext.getSessionManager().getPushSession(sessionId);
		if (session == null) {
			session = pushContext.getSessionFactory().createSession(sessionId);
		}

		String[] topicNames = externalContext.getRequestParameterValuesMap().get(PUSH_TOPIC_PARAM);

		if (topicNames == null) {
			throw new IllegalArgumentException();
		}

		Collection<TopicKey> successfulSubscriptions = session.getSuccessfulSubscriptions();
		List<String> newTopicNames = new ArrayList<String>();
		for (String topicName : topicNames) {
			boolean found = false;
			for (TopicKey topicKey : successfulSubscriptions) {
				if (topicKey.getTopicName().equals(topicName)) {
					found = true;
					break;
				}
			}
			if (!found) {
				newTopicNames.add(topicName);
			}
		}
		session.subscribe(newTopicNames.toArray(new String[0]));

		Map<String, Object> subscriptionData = new HashMap<String, Object>(4);
		subscriptionData.put("sessionId", session.getId());

		Map<TopicKey, String> failedSubscriptions = session.getFailedSubscriptions();
		subscriptionData.put("failures", getFailuresMap(failedSubscriptions));

		Writer outWriter = facesContext.getExternalContext().getResponseOutputWriter();
		ScriptUtils.appendScript(outWriter, subscriptionData);
	}
{code}
                
      was (Author: MilovdZee):
    I changed PushResource.java a little and at first glance it seems to do the trick. I realize that my fix/workaround limits the functionality in that all push clients must have different topic names on one page. Don't know if that was the case before my changes. As far as I can see you could use multiple push components listening to the same topic on one page. Not anymore...

{code title="PushResource.java"}
	public void encode(FacesContext facesContext) throws IOException {
		ExternalContext externalContext = facesContext.getExternalContext();

		PushContextFactory pushContextFactory = ServiceTracker.getService(PushContextFactory.class);

		// resource plugin stub
		if (pushContextFactory == null) {
			return;
		}

		PushContext pushContext = pushContextFactory.getPushContext();

		String forgetPushSessionId = externalContext.getRequestParameterMap().get(FORGET_PUSH_SESSION_ID_PARAM);
		if (forgetPushSessionId != null) {
			Session oldSession = pushContext.getSessionManager().getPushSession(forgetPushSessionId);
			if (oldSession != null) {
				oldSession.invalidate();
			}
		}

		// Session session = pushContext.getSessionFactory().createSession(UUID.randomUUID().toString());
		HttpSession httpSession = (HttpSession)externalContext.getSession(false);
		String sessionId = httpSession.getId();
		Session session = pushContext.getSessionManager().getPushSession(sessionId);
		if (session == null) {
			session = pushContext.getSessionFactory().createSession(sessionId);
		}

		String[] topicNames = externalContext.getRequestParameterValuesMap().get(PUSH_TOPIC_PARAM);

		if (topicNames == null) {
			throw new IllegalArgumentException();
		}

		Collection<TopicKey> successfulSubscriptions = session.getSuccessfulSubscriptions();
		List<String> newTopicNames = new ArrayList<String>();
		for (String topicName : topicNames) {
			boolean found = false;
			for (TopicKey topicKey : successfulSubscriptions) {
				if (topicKey.getTopicName().equals(topicName)) {
					found = true;
					break;
				}
			}
			if (!found) {
				newTopicNames.add(topicName);
			}
		}
		session.subscribe(newTopicNames.toArray(new String[0]));

		Map<String, Object> subscriptionData = new HashMap<String, Object>(4);
		subscriptionData.put("sessionId", session.getId());

		Map<TopicKey, String> failedSubscriptions = session.getFailedSubscriptions();
		subscriptionData.put("failures", getFailuresMap(failedSubscriptions));

		Writer outWriter = facesContext.getExternalContext().getResponseOutputWriter();
		ScriptUtils.appendScript(outWriter, subscriptionData);
	}
{code}
                  
> Push: Test that messages do not become stale in a queue
> -------------------------------------------------------
>
>                 Key: RF-12219
>                 URL: https://issues.jboss.org/browse/RF-12219
>             Project: RichFaces
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: component-push/poll
>    Affects Versions: 4.2.1.Final
>            Reporter: Lukáš Fryč
>            Assignee: Juraj Huska
>            Priority: Critical
>             Fix For: 4.3.0.Milestone1
>
>
> According to the [Forum reference],
> we can have problems with stale messages.
> I would suggest to write tests for following scenarios and check that queue is destroyed properly:
> * view expires
> * client leaves the page with {{a4j:push}} without proper clean up
> * ...
> Let's brainstorm other scenarios.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the richfaces-issues mailing list