EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.prototype.framework.utils]

COVERAGE SUMMARY FOR SOURCE FILE [RmiRegistry.java]

nameclass, %method, %block, %line, %
RmiRegistry.java0%   (0/2)0%   (0/10)0%   (0/230)0%   (0/75)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RmiRegistry0%   (0/1)0%   (0/8)0%   (0/215)0%   (0/70)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/3)
RmiRegistry (): void 0%   (0/1)0%   (0/53)0%   (0/20)
bindComponent (String, Remote): void 0%   (0/1)0%   (0/21)0%   (0/5)
getIpFromArguments (String []): String 0%   (0/1)0%   (0/11)0%   (0/3)
lookup (String): Remote 0%   (0/1)0%   (0/49)0%   (0/13)
main (String []): void 0%   (0/1)0%   (0/9)0%   (0/5)
registerComponent (String, Remote, String): void 0%   (0/1)0%   (0/55)0%   (0/16)
startRegistry (): void 0%   (0/1)0%   (0/13)0%   (0/5)
     
class RmiRegistry$10%   (0/1)0%   (0/2)0%   (0/15)0%   (0/6)
RmiRegistry$1 (): void 0%   (0/1)0%   (0/3)0%   (0/2)
run (): void 0%   (0/1)0%   (0/12)0%   (0/4)

1package de.uka.ipd.sdq.prototype.framework.utils;
2 
3import java.io.Serializable;
4import java.net.MalformedURLException;
5import java.rmi.AlreadyBoundException;
6import java.rmi.Naming;
7import java.rmi.NotBoundException;
8import java.rmi.Remote;
9import java.rmi.RemoteException;
10import java.rmi.registry.LocateRegistry;
11import java.rmi.registry.Registry;
12import java.rmi.server.UnicastRemoteObject;
13import java.util.Scanner;
14 
15import de.uka.ipd.sdq.prototype.framework.AbstractScenarioThread;
16 
17public class RmiRegistry extends UnicastRemoteObject implements IRmiRegistry, Serializable {
18 
19        /**
20         * 
21         */
22        private static final long serialVersionUID = 1L;
23 
24        public static final String LOCALHOST = "localhost";
25        
26        private static RmiRegistry singleton;
27        
28        protected static org.apache.log4j.Logger logger = org.apache.log4j.Logger
29                .getLogger(AbstractScenarioThread.class);
30        
31        private RmiRegistry() throws RemoteException
32        {
33                // Locate java RMI registry or create one
34                try {
35                        LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
36                        logger.info("Java RMI registry started");
37                        
38                } catch (RemoteException e) {
39                        LocateRegistry.getRegistry(Registry.REGISTRY_PORT);
40                        logger.info("Java RMI registry already running");
41                }
42                
43                // Create registry binding service if it doesn't exist yet
44                try {
45                        Naming.lookup("//localhost/" + PCM_RMI_REGISTRY);
46                
47                        logger.info("RMI binding service already running");
48                        System.exit(0);
49                        
50                } catch (MalformedURLException e) {                
51                } catch (NotBoundException e) {
52                        logger.info("Starting RMI binding service");
53                        
54                        try {
55                                Naming.bind(PCM_RMI_REGISTRY, this);
56                        } catch (MalformedURLException e2) {
57                                        logger.error("RMI registry failed", e2);
58                        } catch (RemoteException e2) {
59                                        logger.error("RMI registry failed", e2);
60                        } catch (AlreadyBoundException e2) {
61                                        logger.error("RMI registry failed: Registry already bound on this port", e2);
62                        }        
63                }
64        }
65        
66        /* (non-Javadoc)
67         * @see de.uka.ipd.sdq.prototype.framework.IRmiRegistry#bindComponent(java.lang.String, java.rmi.server.UnicastRemoteObject)
68         */
69        public void bindComponent(String name, Remote component) throws RemoteException
70        {
71                logger.info("Binding " + name + " to RMI registry.");
72                try {
73                        java.rmi.Naming.rebind(name, component);
74                } catch (MalformedURLException e) {
75                        logger.error("RMI registry failed", e);
76//                } catch (AlreadyBoundException e) {
77//                        logger.error("RMI Registry failed: Component " + name + " already bound",e);
78                }
79        }
80        
81        public static void startRegistry() 
82        {
83                if (singleton == null) {
84                        try {
85                                singleton = new RmiRegistry();
86                        } catch (RemoteException e) {
87                                logger.error("RMI Registry failed", e);
88                        }
89                }
90        }
91        
92        /**
93         * Registers a component to a RMI registry at the given IP.
94         * @param registryIP        IP of the registry
95         * @param component                instance of the component
96         * @param componentName        unique name of the component
97         */
98        public static void registerComponent(String registryIP, java.rmi.Remote component, String componentName) {
99 
100                try {
101                        Registry reg = LocateRegistry.getRegistry(registryIP);
102 
103                        de.uka.ipd.sdq.prototype.framework.utils.IRmiRegistry pcmRegistry = null;
104                        
105                        while (true) {
106                                try {
107                                        pcmRegistry = (IRmiRegistry) reg.lookup(PCM_RMI_REGISTRY);
108                                        pcmRegistry.bindComponent(componentName, component);
109                                        break;
110                                } catch (RemoteException e) {
111                                        logger.info("RMI registry not found. Next attempt in 3 seconds.");
112                                        Thread.sleep(3000);
113                                } catch (NotBoundException e) {
114                                        logger.info("RMI binding service not found. Next attempt in 3 seconds.");
115                                        Thread.sleep(3000);        
116                                }
117                        }
118 
119                        logger.info(componentName + " bound in registry");
120 
121                } catch (Exception e) {
122                        logger.error(componentName + " err: " + e.getMessage());
123                }
124 
125        }
126        
127        /**
128         * Returns an IP from an argument string array or LOCALHOST instead
129         * @param args
130         * @return
131         */
132        public static String getIpFromArguments(String[] args) {
133                if (args != null && args.length > 0) {
134                        return args[0];
135                }
136                return LOCALHOST;
137        }
138 
139        /**
140         * 
141         * @param name
142         * @return
143         */
144        public static Remote lookup(String name) {
145                Remote result = null;
146 
147                while (true) {
148                        try {                
149                                
150                                result = java.rmi.Naming.lookup(name); 
151                
152                        } catch (java.net.MalformedURLException e) {
153                                logger.error("Remote URI malformed. This should never happen, strange model names used?");
154                        } catch (java.rmi.RemoteException e) {
155                                logger.error("Error while waiting for system. " + e);
156                        } catch (java.rmi.NotBoundException e) {
157                                logger.info("System missing: " + e.getMessage());
158                                try {
159                                        Thread.sleep(3000);
160                                } catch (InterruptedException innerE) {
161                                        logger.error("Error while waiting for system. " + e);
162                                }
163                                continue;
164                        }
165                        
166                        return result;
167                }
168        }
169        
170        
171        public static void main(String[] args)
172        {        
173                startRegistry();
174                
175                logger.info("RMI registry started on port " + Registry.REGISTRY_PORT);
176                
177                new Thread() {
178                        public void run() {
179                                Scanner input = new Scanner(System.in);
180                                if (input.hasNext()) {
181                                        input.nextLine();
182                                }
183                        }
184                }.run();
185        }        
186}

[all classes][de.uka.ipd.sdq.prototype.framework.utils]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov