~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/samples/transporter/custom/client/Client.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20110909140103-o8ucrolqt5g25k57
Tags: upstream-2.5.3.SP1
ImportĀ upstreamĀ versionĀ 2.5.3.SP1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jboss.remoting.samples.transporter.custom.client;
 
2
 
 
3
import org.jboss.remoting.detection.jndi.JNDIDetector;
 
4
import org.jboss.remoting.network.NetworkRegistry;
 
5
import org.jboss.remoting.samples.transporter.basic.Address;
 
6
import org.jboss.remoting.samples.transporter.basic.Customer;
 
7
import org.jboss.remoting.samples.transporter.basic.CustomerProcessor;
 
8
import org.jboss.remoting.samples.transporter.custom.server.JNDIServer;
 
9
import org.jboss.remoting.samples.transporter.custom.server.SocketServer;
 
10
import org.jboss.remoting.transporter.InternalTransporterServices;
 
11
import org.jboss.remoting.transporter.TransporterClient;
 
12
 
 
13
import javax.management.MBeanServer;
 
14
import javax.management.MBeanServerFactory;
 
15
import javax.management.ObjectName;
 
16
import java.net.InetAddress;
 
17
 
 
18
/**
 
19
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
20
 */
 
21
public class Client
 
22
{
 
23
   private String locatorURI = SocketServer.locatorURI;
 
24
 
 
25
   private CustomerProcessor customerProcessor = null;
 
26
 
 
27
   public void makeClientCall() throws Exception
 
28
   {
 
29
      Customer customer = createCustomer();
 
30
 
 
31
      System.out.println("Customer to be processed: " + customer);
 
32
      Customer processedCustomer = customerProcessor.processCustomer(customer);
 
33
      System.out.println("Customer is now: " + processedCustomer);
 
34
 
 
35
      //TransporterClient.destroyTransporterClient(customerProcessor);
 
36
   }
 
37
 
 
38
   public void getCustomerProcessor() throws Exception
 
39
   {
 
40
      initTransporterServices();
 
41
 
 
42
      customerProcessor = (CustomerProcessor) TransporterClient.createTransporterClient(locatorURI, CustomerProcessor.class, true);
 
43
   }
 
44
 
 
45
   private void initTransporterServices() throws Exception
 
46
   {
 
47
      // create MBeanServer
 
48
      MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
 
49
 
 
50
      NetworkRegistry registry = NetworkRegistry.getInstance();
 
51
 
 
52
      String host = InetAddress.getLocalHost().getHostAddress();
 
53
      JNDIDetector jndiDetector = new JNDIDetector();
 
54
      jndiDetector.setPort(JNDIServer.JNDI_PORT);
 
55
      jndiDetector.setHost(host);
 
56
      jndiDetector.setContextFactory("org.jnp.interfaces.NamingContextFactory");
 
57
      jndiDetector.setURLPackage("org.jboss.naming:org.jnp.interfaces");
 
58
 
 
59
 
 
60
      InternalTransporterServices transporterService = InternalTransporterServices.getInstance();
 
61
 
 
62
      transporterService.setup(mbeanServer,
 
63
                               jndiDetector, new ObjectName("remoting:type=Detector,transport=jndi"),
 
64
                               registry, new ObjectName("remoting:type=NetworkRegistry"),
 
65
                               true, true);
 
66
 
 
67
      //TODO: -TME Have to start the detector after setup() call?
 
68
      jndiDetector.start();
 
69
 
 
70
   }
 
71
 
 
72
 
 
73
   private Customer createCustomer()
 
74
   {
 
75
      Customer cust = new Customer();
 
76
      cust.setFirstName("Bob");
 
77
      cust.setLastName("Smith");
 
78
      Address addr = new Address();
 
79
      addr.setStreet("101 Oak Stree");
 
80
      addr.setCity("Atlanta");
 
81
      addr.setZip(30249);
 
82
      cust.setAddr(addr);
 
83
 
 
84
      return cust;
 
85
   }
 
86
 
 
87
   public static void main(String[] args)
 
88
   {
 
89
      org.jboss.remoting.samples.transporter.custom.client.Client client = new org.jboss.remoting.samples.transporter.custom.client.Client();
 
90
      try
 
91
      {
 
92
         client.getCustomerProcessor();
 
93
         while (true)
 
94
         {
 
95
            try
 
96
            {
 
97
               client.makeClientCall();
 
98
               Thread.currentThread().sleep(5000);
 
99
            }
 
100
            catch (Exception e)
 
101
            {
 
102
               e.printStackTrace();
 
103
            }
 
104
         }
 
105
      }
 
106
      catch (Exception e)
 
107
      {
 
108
         e.printStackTrace();
 
109
      }
 
110
   }
 
111
 
 
112
 
 
113
}