KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nserverdemo > NetworkServerUtil


1 /*
2
3    Derby - Class nserverdemo.NetworkServerUtil
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package nserverdemo;
23
24 import java.util.Properties JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.sql.DriverManager JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.sql.Statement JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.sql.SQLWarning JavaDoc;
32 import java.io.PrintWriter JavaDoc;
33 import java.net.InetAddress JavaDoc;
34
35 import org.apache.derby.drda.NetworkServerControl; //derby network server
36
import java.io.FileOutputStream JavaDoc;
37
38 /**
39  * Class for starting the Derby NetworkServer on a separate Thread.
40  * This class provides methods to start, and shutdown the server
41  */

42
43 public class NetworkServerUtil {
44
45     private int portNum;
46     private NetworkServerControl serverControl;
47     private PrintWriter JavaDoc pw;
48
49     public NetworkServerUtil(int port, PrintWriter JavaDoc pw) {
50
51         this.portNum = port;
52         this.pw = pw;
53         try {
54           serverControl = new
55               NetworkServerControl(InetAddress.getByName("localhost"), port);
56           pw.println("Derby Network Server created");
57         } catch (Exception JavaDoc e) {
58             e.printStackTrace();
59           }
60     }
61
62     /**
63      * trace utility of server
64      */

65     public void trace(boolean onoff) {
66       try {
67         serverControl.trace(onoff);
68       } catch (Exception JavaDoc e) {
69           e.printStackTrace();
70         }
71     }
72
73
74     /**
75      * Try to test for a connection
76      * Throws exception if unable to get a connection
77      */

78     public void testForConnection()
79     throws Exception JavaDoc {
80         serverControl.ping();
81     }
82
83
84     /**
85      * Shutdown the NetworkServer
86      */

87     public void shutdown() {
88         try {
89             serverControl.shutdown();
90         } catch (Exception JavaDoc e) {
91             e.printStackTrace();
92         }
93     }
94
95
96     /**
97      * Start Derby Network server
98      *
99      */

100     public void start() {
101         try {
102             serverControl.start(pw);
103         } catch (Exception JavaDoc e) {
104             e.printStackTrace();
105         }
106     }
107
108
109 }
110
111
112
113
Popular Tags