KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > templates > SimpleHorizontalTemplate


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.templates;
26
27 import org.objectweb.cjdbc.controller.core.Controller;
28 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
29 import org.objectweb.cjdbc.scenario.tools.ScenarioConstants;
30 import org.objectweb.cjdbc.scenario.tools.components.ComponentInterface;
31 import org.objectweb.cjdbc.scenario.tools.components.backend.DatabaseManager;
32 import org.objectweb.cjdbc.scenario.tools.components.controller.ControllerManager;
33
34 /**
35  * This class defines a SimpleHorizontalTemplate
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk</a>
38  * @version 1.0
39  */

40 public class SimpleHorizontalTemplate extends Template
41 {
42   protected ControllerManager cm = new ControllerManager();
43   protected DatabaseManager hm = new DatabaseManager();
44   protected ComponentInterface hm1 = null, hm2 = null, hm3 = null, hm4 = null;
45   protected Controller controller1 = null, controller2 = null;
46   protected VirtualDatabase mainVdb1 = null, mainVdb2 = null;
47   protected String JavaDoc port1 = "25322";
48   protected String JavaDoc port2 = "25323";
49
50   /**
51    * @see junit.framework.TestCase#setUp()
52    */

53   protected void setUp()
54   {
55     try
56     {
57       // Start hypersonic databases
58
hm1 = hm.start("9001");
59       hm.loaddatabase("9001");
60       hm2 = hm.start("9002");
61       hm.loaddatabase("9002");
62       hm3 = hm.start("9003");
63       hm.loaddatabase("9003");
64       hm4 = hm.start("9004");
65       hm.loaddatabase("9004");
66
67       // Start controllers
68
// Load controller1
69
controller1 = (Controller) cm.start(port1).getProcess();
70       // Load controller2
71
controller2 = (Controller) cm.start(port2).getProcess();
72     }
73     catch (Exception JavaDoc e)
74     {
75       e.printStackTrace();
76     }
77   }
78   
79   protected void setDatabasesUp(String JavaDoc databaseFileDesc) throws Exception JavaDoc
80   {
81     cm.loaddatabase(port1,databaseFileDesc+"-1.xml");
82     mainVdb1 = controller1.getVirtualDatabase("myDB");
83     mainVdb1.enableAllBackends();
84
85     cm.loaddatabase(port2,databaseFileDesc+"-2.xml");
86     mainVdb2 = controller2.getVirtualDatabase("myDB");
87     mainVdb2.enableAllBackends();
88   }
89
90   /**
91    * @see junit.framework.TestCase#tearDown()
92    */

93   protected void tearDown()
94   {
95     System.out.println("Tearing down horizontal template");
96     cm.stopAll();
97     hm.stopAll();
98
99     int total = (int) ScenarioConstants.WAIT_TIME_BETWEEN_HORIZONTAL_TEST
100         / ScenarioConstants.WAIT_TIME_REFRESH_HORIZONTAL_TEST;
101     System.out.println("Waiting for jgroup to close(" + total + "):");
102     synchronized (this)
103     {
104       for (int i = 0; i < total; i++)
105       {
106         try
107         {
108           System.out.println("*");
109           System.out.flush();
110           wait(ScenarioConstants.WAIT_TIME_REFRESH_HORIZONTAL_TEST);
111         }
112         catch (InterruptedException JavaDoc e)
113         {
114           e.printStackTrace();
115           break;
116         }
117       }
118     }
119     System.out.println("Supposing all jgroups thread have timed out");
120   }
121
122 }
Popular Tags