940db124dd5775794692ebcdf066c1e3f00ef4da
[public/netxms.git] / src / java / netxms-client / src / main / java / org / netxms / client / objects / Cluster.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2010 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.client.objects;
20
21 import java.net.InetAddress;
22 import java.net.UnknownHostException;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.netxms.base.NXCPCodes;
27 import org.netxms.base.NXCPMessage;
28 import org.netxms.client.NXCSession;
29
30 /**
31 * @author victor
32 *
33 */
34 public class Cluster extends GenericObject
35 {
36 private int clusterType;
37 private List<ClusterSyncNetwork> syncNetworks = new ArrayList<ClusterSyncNetwork>(1);
38 private List<ClusterResource> resources = new ArrayList<ClusterResource>();
39 private long zoneId;
40
41 /**
42 * @param msg
43 * @param session
44 */
45 public Cluster(NXCPMessage msg, NXCSession session)
46 {
47 super(msg, session);
48
49 clusterType = msg.getVariableAsInteger(NXCPCodes.VID_CLUSTER_TYPE);
50 zoneId = msg.getVariableAsInt64(NXCPCodes.VID_ZONE_ID);
51
52 int count = msg.getVariableAsInteger(NXCPCodes.VID_NUM_SYNC_SUBNETS);
53 if (count > 0)
54 {
55 long[] sn = msg.getVariableAsUInt32Array(NXCPCodes.VID_SYNC_SUBNETS);
56 for(int i = 0; i < sn.length;)
57 {
58 InetAddress addr = inetAddressFromInt32(sn[i++]);
59 InetAddress mask = inetAddressFromInt32(sn[i++]);
60 syncNetworks.add(new ClusterSyncNetwork(addr, mask));
61 }
62 }
63
64 count = msg.getVariableAsInteger(NXCPCodes.VID_NUM_RESOURCES);
65 long baseId = NXCPCodes.VID_RESOURCE_LIST_BASE;
66 for(int i = 0; i < count; i++, baseId += 10)
67 {
68 resources.add(new ClusterResource(msg, baseId));
69 }
70 }
71
72 /**
73 * Create InetAddress object from 32bit integer
74 *
75 * @param intVal
76 * @return
77 */
78 private InetAddress inetAddressFromInt32(long intVal)
79 {
80 final byte[] addr = new byte[4];
81 InetAddress inetAddr;
82
83 addr[0] = (byte)((intVal & 0xFF000000) >> 24);
84 addr[1] = (byte)((intVal & 0x00FF0000) >> 16);
85 addr[2] = (byte)((intVal & 0x0000FF00) >> 8);
86 addr[3] = (byte)(intVal & 0x000000FF);
87
88 try
89 {
90 inetAddr = InetAddress.getByAddress(addr);
91 }
92 catch(UnknownHostException e)
93 {
94 inetAddr = null;
95 }
96 return inetAddr;
97 }
98
99 /**
100 * @return the clusterType
101 */
102 public int getClusterType()
103 {
104 return clusterType;
105 }
106
107 /**
108 * @return the syncNetworks
109 */
110 public List<ClusterSyncNetwork> getSyncNetworks()
111 {
112 return syncNetworks;
113 }
114
115 /**
116 * @return the resources
117 */
118 public List<ClusterResource> getResources()
119 {
120 return resources;
121 }
122
123 /* (non-Javadoc)
124 * @see org.netxms.client.NXCObject#getObjectClassName()
125 */
126 @Override
127 public String getObjectClassName()
128 {
129 return "Cluster";
130 }
131
132 /**
133 * @return the zoneId
134 */
135 public long getZoneId()
136 {
137 return zoneId;
138 }
139 }