/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/**
* The hierarchy of directories above a running DAS or server instance can get
* messy to deal with -- thus this class. This class is a bullet-proof holder of
* that information.
*
* Instances and DAS are arranged differently:
*
* examples:
* DAS
* domainDir = getServerDir() == C:/glassfish3/glassfish/domains/domain1
* domainsDir = getServerParentDir() == C:/glassfish3/glassfish/domains
* grandparent-dir is meaningless
*
* Instance
* instanceDir = getServerDir() == C:/glassfish3/glassfish/nodes/mymachine/instance1
* agentDir = getServerParentDir() == C:/glassfish3/glassfish/nodes/mymachine
* agentsDir = getServerGrandParentDir() == C:/glassfish3/glassfish/nodes
*
* Currently in all cases the name of the serverDir is the name of the server --
* by our definition.
*
* THIS CLASS IS GUARANTEED THREAD SAFE
* THIS CLASS IS GUARANTEED IMMUTABLE
*
* Contract: Caller is supposed to NOT call methods on an instance of this class.
* It's "advanced java" to be able to do that anyway.
* I don't allow half-baked data out. It's all or none. The "valid" flag
* is checked and if invalid -- all methods return null. They don't throw an Exception
* because the caller is not supposed to call the methods - it would just annoy
* the caller.
*
* @author Byron Nevins
* @since 3.1
* Created: April 19, 2010
*/
public class ServerDirs {
// do-nothing constructor
/**
*
*/
public ServerDirs() {
serverName = null;
valid = false;
}
if (!leaf.isDirectory())
// note that serverDir has been "smart-filed" so we don't have to worry
// about getParentFile() which has issues with relative paths...
// grandparent dir is optional. It can be null for DAS for instance...
BufferedReader r = null;
try {
localPasswordBuffer = r.readLine();
}
catch (Exception e) {
// needs no handling
}
finally {
if (r != null) {
try {
r.close();
}
catch (IOException ex) {
// ignore
}
}
}
// bnevins May 17 -- perhaps we should have a NodeAgentDirs ???
valid = true;
}
if (!valid)
return null;
return serverName;
}
/**
* Return a message suitable for printing, not just for errors.
* @return
*/
if (!valid)
return "Internal Error: ServerDirs is in an invalid state";
return null;
// Hmmm... can't delete it, don't use it
// TODO -- try to go inside it and delete the contents
return message + " Couldn't remove pid file";
}
return message;
}
return new ServerDirs(serverDir);
}
// getters & setters section below
if (!valid)
return null;
return serverDir;
}
if (!valid)
return null;
return agentDir;
}
if (!valid)
return null;
return parentDir;
}
if (!valid)
return null;
return grandParentDir;
}
if (!valid)
return null;
return domainXml;
}
if (!valid)
return null;
return configDir;
}
if (!valid)
return null;
return pidFile;
}
return dasPropertiesFile;
}
return localPassword;
}
if (!valid)
return null;
return localPasswordFile;
}
public final boolean isValid() {
return valid;
}
return ObjectAnalyzer.toString(this);
}
///////////////////////////////////////////////////////////////////////////
/////////// All Private Below /////////////////////////
///////////////////////////////////////////////////////////////////////////
private final boolean valid;
// Can be shared among classes in the package
}