Author: woonsan Date: Tue Jul 16 18:36:28 2013 New Revision: 1503820 URL: http://svn.apache.org/r1503820 Log: JS2-1285: code formatting
Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/cluster/NodeManagerImpl.java Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/cluster/NodeManagerImpl.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/cluster/NodeManagerImpl.java?rev=1503820&r1=1503819&r2=1503820&view=diff ============================================================================== --- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/cluster/NodeManagerImpl.java (original) +++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/cluster/NodeManagerImpl.java Tue Jul 16 18:36:28 2013 @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,10 +30,10 @@ import org.springframework.beans.factory import org.springframework.beans.factory.BeanFactoryAware; /** - * Node Manager + * Node Manager * * @author <a href="mailto:h...@bluesunrise.com">Hajo Birthelmer</a> - * @version + * @version $Id$ */ public class NodeManagerImpl implements NodeManager,BeanFactoryAware { @@ -44,118 +44,144 @@ public class NodeManagerImpl implements */ private BeanFactory beanFactory; - private HashMap<String, NodeInformation> nodes = null; - private File rootIndexDir = null; - + private HashMap<String, NodeInformation> nodes = null; + private File rootIndexDir = null; + /** the default criterion bean name */ private String nodeInformationBean = "NodeInformation"; - - public NodeManagerImpl(String indexRoot, String nodeInformationBean) - throws Exception + + public NodeManagerImpl(String indexRoot, String nodeInformationBean) throws Exception { - //assume it's full path for now rootIndexDir = new File(indexRoot); this.nodeInformationBean = nodeInformationBean; if (!(rootIndexDir.exists())) - rootIndexDir.mkdirs(); + { + rootIndexDir.mkdirs(); + } + load(); } - - protected void save() - { - try { - FileOutputStream fout = new FileOutputStream(rootIndexDir.getAbsolutePath()+ "/nodeInfo.ser"); - ObjectOutputStream oos = new ObjectOutputStream(fout); - oos.writeObject(nodes); - oos.close(); - } - catch (Exception e) - { - log.error("Failed to write nodes data file to " + rootIndexDir.getAbsolutePath()+ "/nodeInfo.ser" + " - error : " + e.getLocalizedMessage()); - e.printStackTrace(); - } - } - - @SuppressWarnings("unchecked") + + protected void save() + { + try + { + FileOutputStream fout = new FileOutputStream(rootIndexDir.getAbsolutePath() + "/nodeInfo.ser"); + ObjectOutputStream oos = new ObjectOutputStream(fout); + oos.writeObject(nodes); + oos.close(); + } + catch (Exception e) + { + log.error("Failed to write nodes data file to " + rootIndexDir.getAbsolutePath() + "/nodeInfo.ser" + " - error : " + e.getLocalizedMessage()); + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") protected void load() - { - File data = new File( rootIndexDir.getAbsolutePath()+ "/nodeInfo.ser"); - if (data.exists()) - { - try { - FileInputStream fin = new FileInputStream(data.getAbsolutePath()); - ObjectInputStream ois = new ObjectInputStream(fin); - nodes = (HashMap<String,NodeInformation>) ois.readObject(); - ois.close(); - } - catch (Exception e) - { - log.error("Failed to read nodes data file from " + data.getAbsolutePath() + " - error : " + e.getLocalizedMessage()); - nodes = new HashMap<String,NodeInformation>(); - } - } - else - { - try - { - data.createNewFile(); - } - catch (Exception e) - { - log.error("Failed to create new nodes data file error : " + e.getLocalizedMessage()); - e.printStackTrace(); - } - nodes = new HashMap<String,NodeInformation>(); - } - -// NodeInformationImpl temp = new NodeInformationImpl(); -// temp.setContextName("tttt"); - } - public synchronized int checkNode(Long revision, String contextName) - { - if ((contextName == null) || (revision == null)) - return NodeManager.INVALID_NODE_REQUEST; - NodeInformation info = (NodeInformation)nodes.get(contextName); - if (info == null) - return NodeManager.NODE_NEW; - if (info.getRevision().longValue() < revision.longValue()) - return NodeManager.NODE_OUTDATED; - return NodeManager.NODE_SAVED; - } - - public synchronized void addNode(Long revision, String contextName) throws Exception - { - if ((contextName == null) || (revision == null)) - return; - NodeInformation info = (NodeInformation)nodes.get(contextName); - if (info == null) - { - info = createNodeInformation(); - info.setContextName(contextName); - } - info.setRevision(revision); - nodes.put(contextName, info); - save(); - } - - public synchronized void removeNode(String contextName) throws Exception - { - if (contextName == null) - return; - NodeInformation info = (NodeInformation)nodes.get(contextName); - if (info == null) - return; - nodes.remove(contextName); - save(); - } - + { + File data = new File(rootIndexDir.getAbsolutePath() + "/nodeInfo.ser"); + + if (data.exists()) + { + try + { + FileInputStream fin = new FileInputStream(data.getAbsolutePath()); + ObjectInputStream ois = new ObjectInputStream(fin); + nodes = (HashMap<String, NodeInformation>) ois.readObject(); + ois.close(); + } + catch (Exception e) + { + log.error("Failed to read nodes data file from " + data.getAbsolutePath() + " - error : " + e.getLocalizedMessage()); + nodes = new HashMap<String, NodeInformation>(); + } + } + else + { + try + { + data.createNewFile(); + } + catch (Exception e) + { + log.error("Failed to create new nodes data file error : " + e.getLocalizedMessage()); + e.printStackTrace(); + } + nodes = new HashMap<String, NodeInformation>(); + } + // NodeInformationImpl temp = new NodeInformationImpl(); + // temp.setContextName("tttt"); + } + + public synchronized int checkNode(Long revision, String contextName) + { + if ((contextName == null) || (revision == null)) + { + return NodeManager.INVALID_NODE_REQUEST; + } + + NodeInformation info = (NodeInformation) nodes.get(contextName); + + if (info == null) + { + return NodeManager.NODE_NEW; + } + + if (info.getRevision().longValue() < revision.longValue()) + { + return NodeManager.NODE_OUTDATED; + } + + return NodeManager.NODE_SAVED; + } + + public synchronized void addNode(Long revision, String contextName) throws Exception + { + if ((contextName == null) || (revision == null)) + { + return; + } + + NodeInformation info = (NodeInformation) nodes.get(contextName); + + if (info == null) + { + info = createNodeInformation(); + info.setContextName(contextName); + } + + info.setRevision(revision); + nodes.put(contextName, info); + save(); + } + + public synchronized void removeNode(String contextName) throws Exception + { + if (contextName == null) + { + return; + } + + NodeInformation info = (NodeInformation) nodes.get(contextName); + + if (info == null) + { + return; + } + + nodes.remove(contextName); + save(); + } + /* * (non-Javadoc) - * + * * @see org.apache.jetspeed.profiler.Profiler#createRuleCriterion() */ protected NodeInformation createNodeInformation() throws ClassNotFoundException @@ -165,7 +191,8 @@ public class NodeManagerImpl implements NodeInformation nodeInformation = (NodeInformation) beanFactory.getBean( this.nodeInformationBean, NodeInformation.class); return nodeInformation; - } catch (Exception e) + } + catch (Exception e) { log.error("Failed to create nodeInformation for " + nodeInformationBean + " error : " + e.getLocalizedMessage()); @@ -177,7 +204,7 @@ public class NodeManagerImpl implements /* * Method called automatically by Spring container upon initialization - * + * * @param beanFactory automatically provided by framework @throws * BeansException */ @@ -186,8 +213,8 @@ public class NodeManagerImpl implements this.beanFactory = beanFactory; } - public synchronized int getNumberOfNodes() - { - return nodes.size(); - } + public synchronized int getNumberOfNodes() + { + return nodes.size(); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscr...@portals.apache.org For additional commands, e-mail: jetspeed-dev-h...@portals.apache.org