KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > rmi > iiop > util > RmiIiopUtility


1 /**
2  * Copyright (C) 2004-2005 - Bull S.A.
3  *
4  * CAROL: Common Architecture for RMI ObjectWeb Layer
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: RmiIiopUtility.java,v 1.2 2005/03/10 09:51:46 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.carol.rmi.iiop.util;
27
28 import java.io.IOException JavaDoc;
29
30 import javax.naming.InitialContext JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32 import javax.rmi.CORBA.Stub JavaDoc;
33
34 import org.omg.CORBA.BAD_OPERATION JavaDoc;
35 import org.omg.CORBA.ORB JavaDoc;
36 import org.omg.CORBA.portable.ObjectImpl JavaDoc;
37
38 import org.objectweb.carol.util.configuration.TraceCarol;
39
40 /**
41  * Utility class for the rmi iiop protocol
42  *
43  * @author Benoit Pelletier
44  */

45 public class RmiIiopUtility {
46
47     /**
48      * private constructor mandatory for utilities class
49      *
50      */

51     private RmiIiopUtility() {
52     }
53
54     /**
55      * Connect a stub to an ORB
56      *
57      * @param object object to connect
58      * @throws IOException exception
59      */

60     public static void reconnectStub2Orb(Object JavaDoc object) throws IOException JavaDoc {
61
62         if (TraceCarol.isDebugRmiCarol()) {
63             TraceCarol.debugRmiCarol("object=" + object);
64         }
65         // get the current protocol
66
if (object instanceof ObjectImpl JavaDoc) {
67            try {
68               // Check we are still connected
69
ObjectImpl JavaDoc objectImpl = (ObjectImpl JavaDoc) object;
70               objectImpl._get_delegate();
71               if (TraceCarol.isDebugRmiCarol()) {
72                   TraceCarol.debugRmiCarol("still connected to ORB");
73               }
74            } catch (BAD_OPERATION JavaDoc e) {
75               try {
76                  // Reconnect
77
if (TraceCarol.isDebugRmiCarol()) {
78                      TraceCarol.debugRmiCarol("must be reconnect to ORB");
79                  }
80                  Stub JavaDoc stub = (Stub JavaDoc) object;
81                  ORB JavaDoc orb = (ORB JavaDoc) new InitialContext JavaDoc().lookup("java:comp/ORB");
82                  // unable to use PortableRemoteObject.connect here because not implemented
83
// in JacOrb
84
stub.connect(orb);
85                  if (TraceCarol.isDebugRmiCarol()) {
86                      TraceCarol.debugRmiCarol("reconnected");
87                  }
88               } catch (NamingException JavaDoc ne) {
89                  throw new IOException JavaDoc("Unable to lookup java:comp/ORB");
90               }
91            }
92         } else {
93            throw new IOException JavaDoc("Not an ObjectImpl " + object.getClass().getName());
94         }
95     }
96 }
Popular Tags