[JBoss Seam] - Stafull session bewn - set new reference
by kooudy
I have a question:
I have statefull bean:
@Stateful
| @Scope(ScopeType.SESSION)
| @Name("hotelSearch")
| public class HotelSearch implements HotelSearchLocalIF {
| @DataModelSelection
| private Hotel hotel;
|
| @DataModel
| private List<Hotel> hotelList;
|
| /**
| * Set new hotel.
| */
| public void setHotel(Hotel hotel) {
| this.hotel = hotel;
| }
|
| private void logHotel() {
| log.debug(this.hotel);
| }
|
| }
I call hotel.setHotel(newHotel) from another stateless bean to set new detail.
Then I call logHotel() but there is original hotel logged
(which was in variable hotel before setting new one).
It looks like method setHote(hotel) sets new detail only for setHotel() method duration. But after this method ends, original hotel is injected.
When I want to change hotel, I have to change attributes of hotel, but not whole instance (reference):
public void setHotel(Hotel hotel) {
| // this.hotel = hotel; //not works, after methodends, there is original hotel injected
|
| //ne approach to update hotel detail
| this.hotel.setId(hotel.getId);
| this.hotel.setName(hotel.getName);
| ...
| }
Can I force HotelSearch to set new hotel reference for HotelSearch?
I have met this several times and I don't now the right solution.
I have tried the same with @In and behaviour is similar.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4067684#4067684
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4067684
18Â years, 9Â months
[Microcontainer] - How to emulate ServiceMBeanSupport using AOP
by genman
I got this to work, it's pretty slick actually... Thanks Ales.
Service.java :
| /**
| * Interface defines the basic operations for a service.
| */
| public interface Service {
|
| /**
| * Possible states for a service.
| */
| enum State {
| /**
| * Initial state; no lifecycle methods called.
| */
| INITIAL,
| /**
| * Created state; dependencies not ready.
| */
| CREATED,
| /**
| * Started state; dependencies in started state.
| */
| STARTED,
| /**
| * Stopped state; dependencies also stopped.
| */
| STOPPED,
| /**
| * Destroyed state.
| */
| DESTROYED
| }
|
| /**
| * Starts the service
| * @throws Exception if this lifecycle method failed
| */
| public void start() throws Exception;
|
| /**
| * Starts the service
| * @throws Exception if this lifecycle method failed
| */
| public void stop() throws Exception;
|
| /**
| * Creates the service
| * @throws Exception if this lifecycle method failed
| */
| public void create() throws Exception;
|
| /**
| * Destroys the service
| * @throws Exception if this lifecycle method failed
| */
| public void destroy() throws Exception;
|
| /**
| * Returns the service state; or null if not known.
| */
| public State getState();
|
| /**
| * Returns the service name; or null if not known.
| */
| public String getName();
| }
|
LifecycleInterceptor.java:
| public class LifecycleInterceptor {
|
| private Log log = LogFactory.getLog(getClass());
|
| private Kernel kernel;
|
| /**
| * Maps the service method names to controller states.
| */
| private enum Methods {
|
| start(ControllerState.INSTALLED),
| stop(ControllerState.CREATE),
| create(ControllerState.CREATE),
| destroy(ControllerState.INSTANTIATED);
|
| private ControllerState cs;
|
| Methods(ControllerState cs) {
| this.cs = cs;
| }
|
| public ControllerState getState() {
| return cs;
| }
| };
|
| private boolean calledByKernel() {
| // The following detects if the kernel is calling us
| StackTraceElement[] sta = Thread.currentThread().getStackTrace();
| for (StackTraceElement se : sta) {
| String c = se.getClassName();
| if (c.startsWith("org.jboss.kernel"))
| return true;
| }
| return false;
| }
|
| /**
| * Determines the controller context, by method name chooses
| * and sets new controller state in the kernel.
| *
| * If called by the kernel, returns.
| *
| * @param inv method invocation
| */
| public Object handle(Invocation inv) throws Throwable {
| Service target = (Service) inv.getTargetObject();
|
| if (calledByKernel())
| return inv.invokeNext();
|
| KernelController controller = kernel.getController();
| ControllerContext context;
| MethodInvocation minv = (MethodInvocation)inv;
| String mname = minv.getMethod().getName();
| context = kernel.getController().getContext(target.getName(), null);
| if (context == null) {
| log.debug("service not installed " + target.getName());
| return inv.invokeNext();
| }
|
| // We assume the method call is a lifecycle method (by configuration)
| ControllerState state = Methods.valueOf(mname).getState();
| log.debug("controller change " + target.getName() + " to " + state.getStateString() + " for " + mname + "()");
| controller.change(context, state);
| return null;
| }
|
| /**
| * Returns kernel.
| */
| public Kernel getKernel() {
| return kernel;
| }
|
| /**
| * Sets kernel.
| */
| public void setKernel(Kernel kernel) {
| this.kernel = kernel;
| }
|
| }
|
-beans.xml declaration:
| <aop:aspect xmlns:aop="urn:jboss:aop-beans:1.0"
| name="LifecycleAdvice"
| class="LifecycleInterceptor"
| method="handle"
| pointcut="execution(public void com.autodesk.lbs.service.Service->*())">
| <property name="kernel">
| <inject bean="jboss.kernel:service=Kernel" />
| </property>
| <depends>LifecycleCallback</depends>
| </aop:aspect>
|
One weakness is that the Name has to be stored in the target, there's no way, given a Service to find its name in the Microcontainer. (That I know of.)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4067683#4067683
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4067683
18Â years, 9Â months
[Tomcat, HTTPD, Servlets & JSP] - How do AJP connections get reused?
by ramdas
My application uses JBoss 3.2.6 running Tomcat 5.5 on Debian Linux using the 2.4 kernel. I have not specified the connectionTimeout attribute on the AJP connector between Apache and Tomcat running within JBoss - with the idea that the connections get reused between web requests. 99% of the requests that come into this application are stateless. I notice that the number of Tomcat threads that are being used to KeepAlive the connections between Apache and Tomcat is much higher than the concurrent number of requests coming into Apache. It looks like the connection between Apache and Tomcat is marked as busy and hence Apache picks a new connection to Tomcat and hence ties up a new thread within the Tomcat pool - which over a period of time results in exhaustion of all Tomcat threads. I am thinking of applying connectionTimeouts in order to force these threads to give up Apache connections and restablish new ones- but was wondering why Tomcat holds onto these threads instead of using them for the subsequent Apache requests.
Thanks
Ramdas
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4067681#4067681
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4067681
18Â years, 9Â months