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: ClientFOSFSB.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.MyStatefulHome;
034: import org.objectweb.sampleCluster2.ejb.MyStateful;
035:
036: /**
037: * Fat client :
038: * - test Fail Over of the SFSB
039: */
040: public class ClientFOSFSB {
041:
042: /**
043: * Iteration number
044: */
045: private static final int ITERATION_NB = 50;
046:
047: /**
048: * Main method
049: * @param args arguments of the client
050: */
051: public static int main(String[] args) {
052:
053: String jonasEJBServer = null;
054: String ejbTotalCallsCount = null;
055: String ejbEntityCreated = null;
056: Properties prop = null;
057:
058: // get home
059: MyStatefulHome home = ClientUtility.getMyStatefulHome();
060: System.out.println("Home retrieved -> " + home);
061:
062: // get primary remote
063: MyStateful bean = ClientUtility.getMyStatefulBean(home);
064: System.out.println("Bean created -> " + bean);
065:
066: for (int i = 1; i < ITERATION_NB + 1; i++) {
067: try {
068:
069: String l = "log entry " + i;
070: // add in the bean state
071: bean.logWithJOnASInstance(l);
072:
073: System.out.println("Add " + l);
074:
075: if (0 == (int) i % 10) {
076: System.out
077: .println("------------------------------------------");
078: System.out
079: .println("Get the log entries from the bean state");
080: System.out
081: .println("------------------------------------------");
082: StringBuffer sb = bean.getLogTextDump();
083: System.out.println(sb);
084:
085: System.out
086: .println("------------------------------------------");
087: System.out.println("Sleep 10s");
088: System.out
089: .println("------------------------------------------");
090: try {
091: Thread.sleep(10000);
092: } catch (Exception e) {
093: e.printStackTrace();
094: return -1;
095: }
096: }
097:
098: } catch (Exception e) {
099: e.printStackTrace();
100: return -1;
101: }
102: }
103: try {
104: bean.remove();
105: } catch (Exception e) {
106: e.printStackTrace();
107: return -1;
108: }
109: System.out.println("Client OK. Exiting.");
110: return 0;
111: }
112: }
|