Switching conversation ?

public class Contexts { private static final LogProvider log = Logging.getLogProvider(Contexts.class); static final ThreadLocal applicationContext = new ThreadLocal(); static final ThreadLocal methodContext = new ThreadLocal(); static final ThreadLocal eventContext = new ThreadLocal(); static final ThreadLocal pageContext = new ThreadLocal(); static final ThreadLocal sessionContext = new ThreadLocal(); static final ThreadLocal conversationContext = new ThreadLocal(); static final ThreadLocal businessProcessContext = new ThreadLocal(); }

	System.out.println("================================================");
	System.out.println("CURRENT SESSION ATTRIBUTES");
	System.out.println("================================================");
	HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
	HttpSession session = request.getSession();
	Enumeration<String> nameSessions = session.getAttributeNames();
	String sessionAttrName = null;
	while (nameSessions.hasMoreElements()) {
		sessionAttrName = nameSessions.nextElement();
		System.out.println("["+sessionAttrName + "]=[" + session.getAttribute(sessionAttrName)+"]");
	}
	// CURRENT CONVERSATION DUMP
	System.out.println("================================================");
	System.out.println("CURRENT CONVERSATION DUMP #" + Conversation.instance().getId());
	System.out.println("================================================");
	org.jboss.seam.contexts.ServerConversationContext conversationContext = Contexts.getConversationContext();
	String[] names = conversationContext.getNames();
	for (String name : names) {
		System.out.println("[" + name + "]=[" + conversationContext.get(name)+"]");
	}
	Manager.instance().switchConversation("1");
	// CURRENT CONVERSATION DUMP
	System.out.println("================================================");
	System.out.println("CURRENT CONVERSATION DUMP #1");
	System.out.println("================================================");
	conversationContext = Contexts.getConversationContext();
	names = conversationContext.getNames();
	for (String name : names) {
		System.out.println("[" + name + "]=[" + conversationContext.get(name)+"]");
	}
switchConversation 전후의 CONVERSATION DUMP 를 출력하고 있다. 하지만 결과값은 아래처럼 전후의 인스턴스가 같다. 따라서 Conversation을 격납하는 context 가 switch 되지 않은걸 할 수 있다.
13:42:13,125 INFO [STDOUT] ================================================ 13:42:13,125 INFO [STDOUT] CURRENT SESSION ATTRIBUTES 13:42:13,125 INFO [STDOUT] ================================================ 13:42:13,148 INFO [STDOUT] [org.jboss.seam.CONVERSATION#1$localFileScriptManager]=[jp.co.nri.uniid.nozomi.ep.script.LocalFileScriptManager@3bd24b4f] 13:42:13,148 INFO [STDOUT] [org.jboss.seam.security.rememberMe]=[org.jboss.seam.security.RememberMe@6b4e4e37] 13:42:13,148 INFO [STDOUT] [org.jboss.seam.security.identity]=[org.jboss.seam.security.Identity@61f133ea] 13:42:13,148 INFO [STDOUT] [org.jboss.seam.CONVERSATION#1$org.jboss.seam.persistence.persistenceContexts]=[org.jboss.seam.persistence.PersistenceContexts@228779e2] 13:42:13,148 INFO [STDOUT] [org.jboss.seam.core.conversationEntries]=[ConversationEntries([ConversationEntry(2), ConversationEntry(1)])] 13:42:13,148 INFO [STDOUT] [org.jboss.seam.security.credentials]=[org.jboss.seam.security.Credentials@6c52f623] 13:42:13,148 INFO [STDOUT] [org.jboss.seam.international.localeSelector]=[org.jboss.seam.international.LocaleSelector@3a9dab64] 13:42:13,149 INFO [STDOUT] [org.jboss.seam.CONVERSATION#1$org.jboss.seam.core.conversation]=[org.jboss.seam.core.Conversation@7490d128] 13:42:13,149 INFO [STDOUT] [org.jboss.seam.web.session]=[org.jboss.seam.web.Session@4f93d4e1] 13:42:13,149 INFO [STDOUT] [org.jboss.seam.CONVERSATION#1$org.jboss.seam.international.statusMessages]=[org.jboss.seam.faces.FacesMessages@727d2897] 13:42:13,150 INFO [STDOUT] ================================================ 13:42:13,150 INFO [STDOUT] CURRENT CONVERSATION DUMP #2 13:42:13,150 INFO [STDOUT] ================================================ 13:42:13,160 INFO [STDOUT] [context]=[jp.pe.jo.test.Context@1457e85c] 13:42:13,160 INFO [STDOUT] [org.jboss.seam.core.conversation]=[org.jboss.seam.core.Conversation@1fb10a9f] 13:42:13,161 INFO [STDOUT] [org.jboss.seam.international.statusMessages]=[org.jboss.seam.faces.FacesMessages@20305cfa] 13:42:13,167 INFO [STDOUT] ================================================ 13:42:13,167 INFO [STDOUT] CURRENT CONVERSATION DUMP #1 13:42:13,167 INFO [STDOUT] ================================================ 13:42:13,169 INFO [STDOUT] [context]=[jp.pe.jo.test.Context@1457e85c] 13:42:13,169 INFO [STDOUT] [org.jboss.seam.core.conversation]=[org.jboss.seam.core.Conversation@1fb10a9f] 13:42:13,169 INFO [STDOUT] [org.jboss.seam.international.statusMessages]=[org.jboss.seam.faces.FacesMessages@20305cfa]
세션에서 수동으로 빼서 쓸 수 밖에 없는것일까? 아니면 따로 메소드를 제공하는것일까? 결국은 다시 Redirect 를 해야 Conversation 이 바뀐다… 현재 Conversation 내에서 바로 바꿀 수는 없나보다.. 2013/04/04 Seam은 Conversation등의 Context를 ThreadLocal로 관리하며, Request시에 new 하여 ThreadLocal에 set하고 있다. 따라서 메모리상의 인스턴스는 LRC가 되어야만 Session 에 flush 한다. 동일한 Request상에서 Conversation은 ThreadLocal상에서만 존재하므로 오직 1개 뿐이다. 간단히 switch한다고 해서 ThreadLocal의 내용이 바뀌지는 않는다. switch한뒤에 redirect를 해야 바뀐 cid로 ThreadLocal의 Context가 설정된다. ]]>

Related Posts

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다