KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > application > ServerId


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ServerId.java,v 1.2 2007/01/07 06:14:39 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.application;
23
24 import org.opensubsystems.core.error.OSSException;
25 import org.opensubsystems.core.util.NetUtils;
26
27 /**
28  * This class represents server identification. In general server identification
29  * is an IP address of the machine when it is running. But in some cases such
30  * we may want to run two servers on the same machine and in that case the IP
31  * address is not unique and must be customized by each instance (e.g. using
32  * port or some sequence). Therefore this class is used as and abstraction of
33  * server identification so that we don't rely that it is only and IP address.
34  *
35  * @version $Id: ServerId.java,v 1.2 2007/01/07 06:14:39 bastafidli Exp $
36  * @author Miro Halas
37  * @code.reviewer Miro Halas
38  * @code.reviewed Initial revision
39  */

40 public class ServerId
41 {
42    // Attributes ///////////////////////////////////////////////////////////////
43

44    /**
45     * Identification of the server
46     */

47    protected String JavaDoc m_strServerId;
48    
49    /**
50     * Id of the default server.
51     */

52    protected static ServerId s_defaultServerId;
53    
54    // Constructors /////////////////////////////////////////////////////////////
55

56    /**
57     * Static initializer.
58     */

59    static
60    {
61       try
62       {
63          // We have no setInstance since we just directly generate the default ID
64
s_defaultServerId = new ServerId();
65       }
66       catch (OSSException bfeExc)
67       {
68          // No way to throw checked exception so convert it to unchecked
69
throw new RuntimeException JavaDoc(bfeExc);
70       }
71    }
72       
73    /**
74     * Default constructor.
75     *
76     * @throws OSSException - an error has occured identifying serverr
77     */

78    public ServerId(
79    ) throws OSSException
80    {
81       // By default just use server ip address if somebody wants something
82
// else, they can change it later
83
m_strServerId = NetUtils.getServerIPAddressAndName();
84    }
85    
86    /**
87     * Get the default instance of the server id.
88     *
89     * @return ServerId
90     */

91    public static ServerId getInstance(
92    )
93    {
94       return s_defaultServerId;
95    }
96    
97    /**
98     * Get the server id.
99     *
100     * @return String
101     */

102    public String JavaDoc getServerId(
103    )
104    {
105       return m_strServerId;
106    }
107
108    /**
109     * Set new server id.
110     *
111     * @param serverId - new serverId to set.
112     */

113    public void setServerId(
114       String JavaDoc serverId
115    )
116    {
117       m_strServerId = serverId;
118    }
119 }
120
Popular Tags