KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > derbynet > getCurrentProperties


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.getCurrentProperties
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 package org.apache.derbyTesting.functionTests.tests.derbynet;
22
23 import org.apache.derby.drda.NetworkServerControl;
24 import org.apache.derby.tools.ij;
25
26 import java.util.Properties JavaDoc;
27 import java.sql.*;
28 import java.util.Vector JavaDoc;
29 import java.util.Properties JavaDoc;
30 /**
31     This tests getCurrentProperties
32 */

33
34 public class getCurrentProperties
35 {
36     private static final String JavaDoc DERBY_SYSTEM_HOME = System.getProperty("derby.system.home");
37     
38     private static Properties JavaDoc properties = new java.util.Properties JavaDoc();
39     private static Object JavaDoc joinsync = new Object JavaDoc();
40     private static boolean start = false;
41     public static void main (String JavaDoc args[]) throws Exception JavaDoc
42     {
43         try
44         {
45             NetworkServerControl server = new NetworkServerControl();
46             Properties JavaDoc p = server.getCurrentProperties();
47             p.list(System.out);
48             ij.getPropertyArg(args);
49
50             // create a connection in a different thread
51
startConnection();
52             // wait for connection
53
joinwait();
54             //server.setLogWriter(System.out);
55
// set tracing on for the waiting connection
56
server.trace(3, true);
57             //test NetworkServerControl.logConnections
58
server.logConnections(true);
59             // get properties
60
System.out.println("Properties with tracing on");
61             p = server.getCurrentProperties();
62             p.list(System.out);
63             // set tracing on for all connections
64
server.trace(true);
65             //test NetworkServerControl.setTraceDirectory
66
server.setTraceDirectory(DERBY_SYSTEM_HOME);
67             // get properties
68
System.out.println("Properties with tracing on");
69             p = server.getCurrentProperties();
70             p.list(System.out);
71             joinsignal();
72         }
73         catch (Exception JavaDoc e)
74         {
75             e.printStackTrace();
76         }
77     }
78
79     private static void startConnection()
80     {
81         Runnable JavaDoc service = new Runnable JavaDoc() {
82             public void run() {
83                 try {
84                     Connection conn = ij.startJBMS();
85
86                     // signal that connection has been established
87
joinsignal();
88                     joinwait();
89                 }
90                 catch (Exception JavaDoc e) {
91                         throw new RuntimeException JavaDoc(e.getMessage());
92                     }
93                 }
94             };
95             new Thread JavaDoc(service).start();
96     }
97     private static void joinwait()
98     {
99         synchronized(joinsync)
100         {
101             while(!start)
102             {
103                 try
104                 {
105                     joinsync.wait();
106                 }
107                 catch(InterruptedException JavaDoc ie)
108                 {
109                     ie.printStackTrace();
110                 }
111             }
112         start = false;
113         }
114     }
115     private static void joinsignal() throws InterruptedException JavaDoc
116     {
117         synchronized(joinsync)
118         {
119             start = true;
120             joinsync.notifyAll();
121         }
122         Thread.yield();
123         Thread.sleep(10000);
124     }
125 }
126
127
128
Popular Tags