EMMA Coverage Report (generated Wed Jun 28 22:15:27 PDT 2006)
[all classes][org.apache.derby.iapi.jdbc]

COVERAGE SUMMARY FOR SOURCE FILE [DRDAServerStarter.java]

nameclass, %method, %block, %line, %
DRDAServerStarter.java100% (4/4)100% (11/11)77%  (244/317)64%  (50/78)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DRDAServerStarter100% (1/1)100% (5/5)70%  (169/241)60%  (42.1/70)
DRDAServerStarter (): void 100% (1/1)100% (12/12)100% (4/4)
boot (boolean, Properties): void 100% (1/1)64%  (72/112)45%  (14/31)
run (): void 100% (1/1)71%  (29/41)64%  (7/11)
setStartInfo (InetAddress, int, PrintWriter): void 100% (1/1)100% (10/10)100% (4/4)
stop (): void 100% (1/1)70%  (46/66)65%  (13.1/20)
     
class DRDAServerStarter$1100% (1/1)100% (2/2)97%  (37/38)99%  (4/4)
DRDAServerStarter$1 (DRDAServerStarter): void 100% (1/1)100% (6/6)100% (1/1)
run (): Object 100% (1/1)97%  (31/32)98%  (3/3)
     
class DRDAServerStarter$2100% (1/1)100% (2/2)100% (25/25)100% (2/2)
DRDAServerStarter$2 (DRDAServerStarter): void 100% (1/1)100% (6/6)100% (1/1)
run (): Object 100% (1/1)100% (19/19)100% (1/1)
     
class DRDAServerStarter$3100% (1/1)100% (2/2)100% (13/13)100% (2/2)
DRDAServerStarter$3 (DRDAServerStarter): void 100% (1/1)100% (6/6)100% (1/1)
run (): Object 100% (1/1)100% (7/7)100% (1/1)

1/*
2 
3   Derby - Class org.apache.derby.iapi.jdbc.DRDAServerStarter
4 
5   Copyright 2003, 2004 The Apache Software Foundation or its licensors, as applicable.
6 
7   Licensed under the Apache License, Version 2.0 (the "License");
8   you may not use this file except in compliance with the License.
9   You may obtain a copy of the License at
10 
11      http://www.apache.org/licenses/LICENSE-2.0
12 
13   Unless required by applicable law or agreed to in writing, software
14   distributed under the License is distributed on an "AS IS" BASIS,
15   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   See the License for the specific language governing permissions and
17   limitations under the License.
18 
19 */
20 
21package org.apache.derby.iapi.jdbc;
22 
23import org.apache.derby.iapi.services.sanity.SanityManager;
24import org.apache.derby.iapi.services.monitor.Monitor;
25import org.apache.derby.iapi.services.monitor.ModuleControl;
26import org.apache.derby.iapi.reference.MessageId;
27import org.apache.derby.iapi.reference.Property;
28import java.io.PrintWriter;
29import java.lang.Runnable;
30import java.lang.Thread;
31import java.lang.reflect.Constructor;
32import java.lang.reflect.Method;
33import java.lang.reflect.InvocationTargetException;
34import java.net.InetAddress;
35import java.security.AccessController;
36import java.security.PrivilegedActionException;
37import java.security.PrivilegedExceptionAction;
38 
39public final class DRDAServerStarter implements ModuleControl, Runnable
40{
41 
42    private Object server;
43    private Method serverStartMethod;
44        private Method serverShutdownMethod;
45    private boolean loadSysIBM;
46    private Thread serverThread;
47    private static final String serverClassName = "org.apache.derby.impl.drda.NetworkServerControlImpl";
48    private Class serverClass;
49        
50        private InetAddress listenAddress =null;
51        private int portNumber = -1;
52        private PrintWriter consoleWriter = null;
53 
54    /**
55     * Try to start the DRDA server. Log an error in error log and continue if it cannot be started.
56     */
57//     public static void start()
58//     {
59 
60 
61        public void setStartInfo(InetAddress listenAddress, int portNumber, PrintWriter
62                                                         consoleWriter)
63        {
64                this.listenAddress = listenAddress;
65                this.portNumber = portNumber;
66                this.consoleWriter = consoleWriter;
67        }
68 
69 
70 
71    public void boot(boolean create,
72                     java.util.Properties properties)
73    {
74        if( server != null)
75        {
76            if (SanityManager.DEBUG)
77                SanityManager.THROWASSERT( "Network server starter module booted twice.");
78            return;
79        }
80        // Load the server class indirectly so that Cloudscape does not require the network code
81        try
82        {
83            serverClass = Class.forName( serverClassName);
84        }
85        catch( ClassNotFoundException cnfe)
86        {
87            Monitor.logTextMessage( MessageId.CONN_NETWORK_SERVER_CLASS_FIND, serverClassName);
88            return;
89        }
90        catch( java.lang.Error e)
91        {
92            Monitor.logTextMessage( MessageId.CONN_NETWORK_SERVER_CLASS_LOAD,
93                                    serverClassName,
94                                    e.getMessage());
95            return;
96        }
97        try
98        {
99            Constructor  serverConstructor;
100            try
101            {
102                serverConstructor = (Constructor) AccessController.doPrivileged(
103                              new PrivilegedExceptionAction() {
104                                                  public Object run() throws NoSuchMethodException, SecurityException
105                                                  {
106                                                          if (listenAddress == null)
107                                                                  return serverClass.getConstructor(null);
108                                                          else
109                                                                  return
110                                                                          serverClass.getConstructor(new
111                                                                                  Class[] {java.net.InetAddress.class,
112                                                                                                   Integer.TYPE});}
113                                          }
114                                  );
115                                serverStartMethod = (Method) AccessController.doPrivileged(
116                                   new PrivilegedExceptionAction() {
117                                                   public Object run() throws NoSuchMethodException, SecurityException
118                                                   { return serverClass.getMethod( "blockingStart", new Class[] { java.io.PrintWriter.class});}
119                                           }
120                                   );
121                                
122                                serverShutdownMethod = (Method) AccessController.doPrivileged(
123                                   new PrivilegedExceptionAction() {
124                                                   public Object run() throws NoSuchMethodException, SecurityException
125                                                   { return serverClass.getMethod( "directShutdown", null);}
126                                           }
127                                   );
128            }
129            catch( PrivilegedActionException e)
130            {
131                Exception e1 = e.getException();
132                Monitor.logTextMessage(
133                                                                           MessageId.CONN_NETWORK_SERVER_START_EXCEPTION, e1.getMessage());
134                                e.printStackTrace(Monitor.getStream().getPrintWriter());
135                return;
136 
137            }
138                        if (listenAddress == null)
139                                server = serverConstructor.newInstance( null);
140                        else
141                                server = serverConstructor.newInstance(new Object[]
142                                        {listenAddress, new Integer(portNumber)});
143 
144            serverThread = Monitor.getMonitor().getDaemonThread( this, "NetworkServerStarter", false);
145            serverThread.start();
146        }
147        catch( Exception e)
148        {
149                        Monitor.logTextMessage( MessageId.CONN_NETWORK_SERVER_START_EXCEPTION, e.getMessage());
150                        server = null;
151                        e.printStackTrace(Monitor.getStream().getPrintWriter());
152        }
153    } // end of boot
154 
155    public void run()
156    {
157        try
158        {
159            serverStartMethod.invoke( server,
160                                      new Object[] {consoleWriter });
161        }
162        catch( InvocationTargetException ite)
163        {
164            Monitor.logTextMessage(
165                                                                   MessageId.CONN_NETWORK_SERVER_START_EXCEPTION, ite.getTargetException().getMessage());
166                        ite.printStackTrace(Monitor.getStream().getPrintWriter());
167 
168            server = null;
169        }
170        catch( Exception e)
171        {
172            Monitor.logTextMessage( MessageId.CONN_NETWORK_SERVER_START_EXCEPTION, e.getMessage());
173            server = null;
174                        e.printStackTrace(Monitor.getStream().getPrintWriter());
175        }
176    }
177    
178    public void stop()
179    {
180                try {
181                        if( serverThread != null && serverThread.isAlive())
182                        {
183                                serverShutdownMethod.invoke( server,
184                                                                                         null);
185                                serverThread.interrupt();
186                                serverThread = null;
187                        }
188                   
189                }
190                catch( InvocationTargetException ite)
191        {
192                        Monitor.logTextMessage(
193                                                                   MessageId.CONN_NETWORK_SERVER_SHUTDOWN_EXCEPTION, ite.getTargetException().getMessage());
194                        ite.printStackTrace(Monitor.getStream().getPrintWriter());
195                        
196        }
197        catch( Exception e)
198        {
199            Monitor.logTextMessage( MessageId.CONN_NETWORK_SERVER_SHUTDOWN_EXCEPTION, e.getMessage());
200                        e.printStackTrace(Monitor.getStream().getPrintWriter());
201                }
202                        
203                serverThread = null;
204                server = null;
205                serverClass = null;
206                serverStartMethod = null;
207                serverShutdownMethod = null;
208                listenAddress = null;
209                portNumber = -1;
210                consoleWriter = null;
211                
212    } // end of stop
213}

[all classes][org.apache.derby.iapi.jdbc]
EMMA 2.0.5312 (C) Vladimir Roubtsov