001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005-2006 Bull S.A.S
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s):
022: * --------------------------------------------------------------------------
023: * $Id: ClientLBRemote.java 8414 2006-06-01 13:57:58Z duvauchn $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.sampleCluster2.client;
026:
027: import java.util.Properties;
028:
029: import javax.naming.Context;
030: import javax.naming.InitialContext;
031: import javax.naming.NamingException;
032: import javax.rmi.PortableRemoteObject;
033: import org.objectweb.sampleCluster2.ejb.MyEjb1Home;
034: import org.objectweb.sampleCluster2.ejb.MyEjb1;
035:
036: /**
037: * Fat client :
038: * - access to a SSB
039: * - LB at the remote
040: */
041: public class ClientLBRemote {
042:
043: /**
044: * Iteration number
045: */
046: private static final int ITERATION_NB = 50;
047:
048: /**
049: * Main method
050: * @param args arguments of the client
051: */
052: public static int main(String[] args) {
053:
054: String jonasEJBServer = null;
055: String ejbTotalCallsCount = null;
056: String ejbEntityCreated = null;
057: Properties prop = null;
058:
059: MyEjb1Home home = ClientUtility.getMyEjb1Home();
060: System.out.println("Home retrieved -> " + home);
061: MyEjb1 bean = ClientUtility.getMyEjb1Bean(home);
062: System.out.println("Bean created -> " + bean);
063:
064: for (int i = 1; i < ITERATION_NB + 1; i++) {
065: try {
066:
067: prop = bean.getInfoProps();
068: System.out.println("Bean invoked");
069:
070: jonasEJBServer = prop.getProperty("EJB server");
071: ejbTotalCallsCount = prop
072: .getProperty("EJB total calls");
073: ejbEntityCreated = prop
074: .getProperty("EJB server entity created");
075: } catch (Exception e) {
076: e.printStackTrace();
077: return -1;
078: }
079:
080: System.out.println("\n");
081: System.out.println("Calls=" + i + " - EJB served by jonas="
082: + jonasEJBServer + " - EJB total calls="
083: + ejbTotalCallsCount + " - ejbEntityCreated="
084: + ejbEntityCreated);
085: if (0 == (int) i % 10) {
086: System.out.println("Sleep 10s");
087: try {
088: Thread.sleep(10000);
089: } catch (Exception e) {
090: e.printStackTrace();
091: return -1;
092: }
093: }
094: }
095: try {
096: bean.remove();
097: } catch (Exception e) {
098: e.printStackTrace();
099: return -1;
100: }
101: System.out.println("Client OK. Exiting.");
102: return 0;
103: }
104: }
|