KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > service > bean > ServiceThree


1 /*
2  * JBoss, the OpenSource EJB server
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.service.bean;
8
9 import org.jboss.annotation.ejb.Service;
10 import org.jboss.annotation.ejb.Depends;
11 import org.jboss.annotation.ejb.Depends;
12 import org.jboss.annotation.ejb.Service;
13
14 import javax.ejb.AroundInvoke;
15 import javax.ejb.InvocationContext;
16 import javax.management.ObjectName JavaDoc;
17 import javax.management.MBeanServerFactory JavaDoc;
18 import javax.management.MBeanServer JavaDoc;
19
20 /**
21  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
22  * @version $Revision: 1.2.2.3 $
23  */

24 @Service
25 public class ServiceThree implements ServiceThreeManagement
26 {
27    @Depends ("jboss.j2ee:name=org.jboss.tutorial.service.bean.ServiceOne,service=EJB3,type=service")
28    public ObjectName JavaDoc serviceOneName;
29    private ServiceTwoManagement service2;
30
31    @Depends ("tutorial:service=serviceTwo")
32    public void setServiceTwo(ServiceTwoManagement service2)
33    {
34       this.service2 = service2;
35    }
36
37    public String JavaDoc serviceOneHello()throws Exception JavaDoc
38    {
39       Object JavaDoc[] args = new Object JavaDoc[0];
40       String JavaDoc[] signature = new String JavaDoc[0];
41       System.out.println("ServiceThree - Calling ServiceOne.sayHello() via JMX server");
42       MBeanServer JavaDoc server = (MBeanServer JavaDoc)MBeanServerFactory.findMBeanServer(null).get(0);
43       return (String JavaDoc)server.invoke(serviceOneName, "sayHello", args, signature);
44    }
45
46    public String JavaDoc serviceTwoHello()
47    {
48       System.out.println("ServiceThree - Calling ServiceTwo.sayHello() via MBean proxy");
49       return service2.sayHello();
50    }
51
52    // Interceptors
53
@AroundInvoke
54    public Object JavaDoc intercept(InvocationContext ctx) throws Exception JavaDoc
55    {
56       System.out.println("ServiceThree - Interceptor");
57       return ctx.proceed();
58    }
59
60    // Lifecycle methods
61
public void start() throws Exception JavaDoc
62    {
63       System.out.println("ServiceThree - Starting");
64    }
65
66    public void stop()
67    {
68       System.out.println("ServiceThree - Stopping");
69    }
70
71 }
72
Popular Tags