KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > cluster > ClusterInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ClusterInfo.java
26  *
27  * Created on May 21, 2004, 3:03 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.cluster;
31
32 /**
33  *
34  * @author prakash
35  */

36
37 /*
38  * This class represents one clinstance.conf file.
39  */

40
41 import java.util.*;
42 import java.io.*;
43
44 public class ClusterInfo {
45     
46     // This cluster name is not really extracted from clinstance.conf. This will be the name that is used to create cluster in 8.0.
47
// This is useful in handling rest of cluster processing code.
48
private String JavaDoc clusterName;
49     private List clusteredInstanceList;
50     // This domain nameis added for AS8.x to AS9.0 upgrade
51
private String JavaDoc domainName;
52     private static java.util.logging.Logger JavaDoc log = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger();
53
54     public ClusterInfo(){
55     }
56     public List getClusteredInstanceList(){
57         return this.clusteredInstanceList;
58     }
59     public void parseClinstanceConfFile(File file) throws FileNotFoundException, IOException{
60         if(clusteredInstanceList == null){
61             clusteredInstanceList = new ArrayList();
62         }
63         clusteredInstanceList.clear();
64         BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
65         String JavaDoc line = null;
66         ClusteredInstance clInstance = null;
67         while((line = reader.readLine()) != null){
68             if(line.trim().startsWith("#")){
69                 // Comment line. pass on
70
continue;
71             }
72             if(line.trim().startsWith("instancename")){
73                 String JavaDoc instanceName = line.substring("instancename".length()).trim();
74                 clInstance = createNewInstance(instanceName);
75                 continue;
76             }
77             if(clInstance != null)
78                 clInstance.extractDataFromLine(line);
79         }
80     }
81     private ClusteredInstance createNewInstance(String JavaDoc instanceName){
82         ClusteredInstance clInstance = new ClusteredInstance(instanceName);
83         clusteredInstanceList.add(clInstance);
84         return clInstance;
85     }
86     public ClusteredInstance getMasterInstance(){
87         ClusteredInstance clInstance = null;
88         for(Iterator it = this.clusteredInstanceList.iterator(); it.hasNext();){
89             clInstance = (ClusteredInstance)it.next();
90             if(clInstance.isMaster())
91                 return clInstance;
92         }
93         return null;
94     }
95     public String JavaDoc getDomainName(){
96         if(this.domainName == null){
97             ClusteredInstance clInstance = this.getMasterInstance();
98             if((clInstance == null) && (this.clusteredInstanceList.size() > 0)){
99                 clInstance = (ClusteredInstance)this.clusteredInstanceList.get(0);
100             }
101             this.domainName = clInstance.getDomain();
102             return clInstance.getDomain();
103         }
104         return this.domainName;
105     }
106     public void setDomainName(String JavaDoc dName){
107         this.domainName = dName;
108     }
109     public String JavaDoc getClusterName(){
110         return this.clusterName;
111     }
112     public void setClusterName(String JavaDoc clName){
113         this.clusterName = clName;
114     }
115     public void print(){
116         if(clusteredInstanceList != null){
117             for(Iterator it = clusteredInstanceList.iterator(); it.hasNext();){
118                 ClusteredInstance clInst = (ClusteredInstance)it.next();
119                 log.info(clInst.getInstanceName());
120                 log.info(clInst.getUser());
121                 log.info(clInst.getHost());
122                 log.info(clInst.getPort());
123                 log.info(clInst.getDomain());
124                 log.info(clInst.getInstancePort());
125                 log.info(String.valueOf(clInst.isMaster()));
126                 log.info("\n");
127             }
128         }
129     }
130 }
131
Popular Tags