+ * Based on Spring's JPetStore sample, written by Juergen Hoeller. + *
+ * + * @author Ben Alex + */ +public class ClientApplication { + //~ Instance fields ======================================================== + + private final ListableBeanFactory beanFactory; + + //~ Constructors =========================================================== + + public ClientApplication(ListableBeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + + //~ Methods ================================================================ + + public void invokeContactManager(String username, int nrOfCalls) { + StopWatch stopWatch = new StopWatch(nrOfCalls + + " ContactManager call(s)"); + Map orderServices = this.beanFactory.getBeansOfType(ContactManager.class, + true, true); + + for (Iterator it = orderServices.keySet().iterator(); it.hasNext();) { + String beanName = (String) it.next(); + + ContactManager remoteContactManager = (ContactManager) orderServices + .get(beanName); + System.out.println("Calling ContactManager '" + beanName + + "' for owner " + username); + stopWatch.start(beanName); + + Contact[] contacts = null; + + for (int i = 0; i < nrOfCalls; i++) { + contacts = remoteContactManager.getAllByOwner(username); + } + + stopWatch.stop(); + + if (contacts.length != 0) { + for (int i = 0; i < contacts.length; i++) { + System.out.println("Contact " + i + ": " + + contacts[i].toString()); + } + } else { + System.out.println("No contacts found belonging to owner"); + } + + System.out.println(); + } + + System.out.println(stopWatch.prettyPrint()); + } + + public static void main(String[] args) { + if ((args.length == 0) || "".equals(args[0])) { + System.out.println( + "You need to specify a user ID and optionally a number of calls, e.g. for user marissa: " + + "'client marissa' for a single call per service or 'client marissa 10' for 10 calls each"); + } else { + String username = args[0]; + int nrOfCalls = 1; + + if ((args.length > 1) && !"".equals(args[1])) { + nrOfCalls = Integer.parseInt(args[1]); + } + + ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext( + "clientContext.xml"); + ClientApplication client = new ClientApplication(beanFactory); + client.invokeContactManager(username, nrOfCalls); + } + } +} diff --git a/samples/contacts/war/WEB-INF/caucho-servlet.xml b/samples/contacts/war/WEB-INF/caucho-servlet.xml new file mode 100644 index 0000000000..b28b7b03ae --- /dev/null +++ b/samples/contacts/war/WEB-INF/caucho-servlet.xml @@ -0,0 +1,28 @@ + + + + +