Skip to content

Commit cde8f7b

Browse files
author
Myron Scott
committed
fix directory properties. create the ability to designate the server jar
1 parent 1f0b655 commit cde8f7b

File tree

7 files changed

+67
-160
lines changed

7 files changed

+67
-160
lines changed

default-configuration/src/main/java/org/terracotta/config/provider/DefaultConfigurationProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private Path getConfiguration(String[] args) throws Exception {
224224
return defaultUserHomeConfigurationPath;
225225
}
226226

227-
return Directories.getDefaultConfigFile();
227+
return Directories.getInstallationRoot().resolve("conf/tc-config.xml");
228228
}
229229

230230
private static Options createOptions() {

default-configuration/src/test/java/org/terracotta/config/provider/DefaultConfigurationProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public void testWithDefaultConfigurationInUserDirectory() throws Exception {
278278
public void testWithDefaultConfigurationInInstallationDirectory() throws Exception {
279279
Path temporaryDirectory = temporaryFolder.newFolder("conf").toPath();
280280
System.setProperty(Directories.TC_INSTALL_ROOT_PROPERTY_NAME, temporaryDirectory.getParent().toString());
281-
Files.copy(this.getClass().getResourceAsStream("/simple-tc-config.xml"), Directories.getDefaultConfigFile());
281+
Files.copy(this.getClass().getResourceAsStream("/simple-tc-config.xml"), Directories.getInstallationRoot().resolve("conf/tc-config.xml"));
282282

283283
provider.initialize(Collections.<String>emptyList());
284284

tc-server/src/main/java/com/tc/server/Bootstrap.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ public Future<Boolean> createServer(List<String> args, OutputStream out, ClassLo
116116
return new Future<Boolean>() {
117117
@Override
118118
public boolean cancel(boolean mayInterruptIfRunning) {
119-
server.stop();
120-
return true;
119+
if (server.isStopped()) {
120+
return false;
121+
} else {
122+
server.stop();
123+
return true;
124+
}
121125
}
122126

123127
@Override
@@ -137,6 +141,7 @@ public Boolean get() throws InterruptedException, ExecutionException {
137141

138142
@Override
139143
public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
144+
// for completeness , do not use
140145
long end = System.currentTimeMillis() + unit.toMillis(timeout);
141146
while (System.currentTimeMillis() < end) {
142147
if (!server.isStopped()) {
@@ -147,6 +152,18 @@ public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, Exe
147152
}
148153
throw new TimeoutException();
149154
}
155+
// for galvan compatiblity
156+
public boolean waitUntilShutdown() {
157+
try {
158+
return get();
159+
} catch (ExecutionException | InterruptedException e) {
160+
return false;
161+
}
162+
}
163+
164+
public Object getManagement() {
165+
return server.getManagement();
166+
}
150167
};
151168
}
152169

@@ -365,7 +382,11 @@ public boolean waitUntilShutdown() {
365382
try {
366383
return impl.waitUntilShutdown();
367384
} finally {
368-
TCLogbackLogging.resetLogging();
385+
try {
386+
TCLogbackLogging.resetLogging();
387+
} catch (Exception e) {
388+
// Ignore
389+
}
369390
}
370391
}
371392

terracotta-kit/src/assemble/server/lib/logback-ext.xml

Lines changed: 0 additions & 47 deletions
This file was deleted.

terracotta/src/main/java/com/tc/server/CommonShutDownHook.java

Lines changed: 0 additions & 91 deletions
This file was deleted.

terracotta/src/main/java/com/tc/server/Directories.java

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
package com.tc.server;
2020

2121
import java.io.FileNotFoundException;
22+
import java.io.IOException;
2223
import java.nio.file.Files;
2324
import java.nio.file.Path;
2425
import java.nio.file.Paths;
26+
import java.util.NoSuchElementException;
27+
import java.util.Optional;
2528

2629
/**
2730
* Knows how to find certain directories. You should try <em>everything</em> you can to avoid using this class; using it
@@ -46,15 +49,14 @@ public class Directories {
4649
/**
4750
*/
4851
public static final String TC_SERVER_LIB_PROPERTY_NAME = "tc.server-lib";
52+
/**
53+
*/
54+
public static final String TC_SERVER_JAR_PROPERTY_NAME = "tc.server-jar";
4955
/**
5056
* The property "tc.install-root.ignore-checks", which is used for testing to ignore checks for the installation root
5157
* directory.
5258
*/
5359
public static final String TC_INSTALL_ROOT_IGNORE_CHECKS_PROPERTY_NAME = "tc.install-root.ignore-checks";
54-
/**
55-
* Relative location for default configuration file under Terracotta installation directory
56-
*/
57-
public static final String DEFAULT_CONFIG_FILE_LOCATION = "conf/tc-config.xml";
5860

5961
/**
6062
* Get installation root directory.
@@ -64,7 +66,7 @@ public class Directories {
6466
* @throws FileNotFoundException If {@link #TC_INSTALL_ROOT_IGNORE_CHECKS_PROPERTY_NAME} has not been set,
6567
* this exception may be thrown if the installation root directory is not a directory
6668
*/
67-
static Path getInstallationRoot() throws FileNotFoundException {
69+
public static Path getInstallationRoot() throws FileNotFoundException {
6870
boolean ignoreCheck = Boolean.getBoolean(TC_INSTALL_ROOT_IGNORE_CHECKS_PROPERTY_NAME);
6971
if (ignoreCheck) {
7072
return Paths.get(System.getProperty("user.dir"));
@@ -87,36 +89,58 @@ static Path getInstallationRoot() throws FileNotFoundException {
8789
}
8890
}
8991

90-
public static Path getDefaultConfigFile() throws FileNotFoundException {
91-
return getInstallationRoot().resolve(DEFAULT_CONFIG_FILE_LOCATION);
92+
public static Path getServerJar() throws FileNotFoundException {
93+
String jar = System.getProperty(TC_SERVER_JAR_PROPERTY_NAME);
94+
if (jar == null) {
95+
jar = "tc-server";
96+
}
97+
Path jarFile = searchForServerJar(getServerLibFolder(), jar);
98+
if (jarFile == null) {
99+
jarFile = searchForServerJar(getInstallationRoot(), jar);
100+
}
101+
102+
return jarFile;
103+
}
104+
105+
private static Path searchForServerJar(Path directory, String name) {
106+
try {
107+
Optional<Path> p = Files.list(directory).filter(f->f.getFileName().toString().startsWith(name)).findFirst();
108+
Path option = p.get();
109+
if (Files.exists(option) && Files.isRegularFile(option)) {
110+
return option;
111+
}
112+
return null;
113+
} catch (IOException | NoSuchElementException io) {
114+
return null;
115+
}
92116
}
93117

94118
public static Path getServerLibFolder() throws FileNotFoundException {
95-
String installRoot = System.getProperty(TC_INSTALL_ROOT_PROPERTY_NAME, System.getProperty("user.dir"));
96-
String serverLib = System.getProperty(TC_PLUGINS_LIB_PROPERTY_NAME, "lib");
97-
Path f = Paths.get(installRoot, serverLib);
119+
Path installRoot = getInstallationRoot();
120+
String serverLib = System.getProperty(TC_SERVER_LIB_PROPERTY_NAME, "lib");
121+
Path f = installRoot.resolve(serverLib);
98122
if (!Files.isDirectory(f)) {
99123
throw new FileNotFoundException("server library folder at " + f.toAbsolutePath() + " is not valid");
100124
}
101125
return f;
102126
}
103127

104128
public static Path getServerPluginsApiDir() throws FileNotFoundException {
105-
String installRoot = System.getProperty(TC_INSTALL_ROOT_PROPERTY_NAME, System.getProperty("user.dir"));
129+
Path installRoot = getInstallationRoot();
106130
String pluginsRoot = System.getProperty(TC_PLUGINS_ROOT_PROPERTY_NAME, "plugins");
107131
String pluginsApi = System.getProperty(TC_PLUGINS_API_PROPERTY_NAME, "api");
108-
Path f = Paths.get(installRoot, pluginsRoot, pluginsApi);
132+
Path f = installRoot.resolve(pluginsRoot).resolve(pluginsApi);
109133
if (!Files.isDirectory(f)) {
110134
throw new FileNotFoundException("server plugins api folder at " + f.toAbsolutePath() + " is not valid");
111135
}
112136
return f;
113137
}
114138

115139
public static Path getServerPluginsLibDir() throws FileNotFoundException {
116-
String installRoot = System.getProperty(TC_INSTALL_ROOT_PROPERTY_NAME, System.getProperty("user.dir"));
140+
Path installRoot = getInstallationRoot();
117141
String pluginsRoot = System.getProperty(TC_PLUGINS_ROOT_PROPERTY_NAME, "plugins");
118142
String pluginsLib = System.getProperty(TC_PLUGINS_LIB_PROPERTY_NAME, "lib");
119-
Path f = Paths.get(installRoot, pluginsRoot, pluginsLib);
143+
Path f = installRoot.resolve(pluginsRoot).resolve(pluginsLib);
120144
if (!Files.isDirectory(f)) {
121145
throw new FileNotFoundException("server plugins implementations folder at " + f.toAbsolutePath() + " is not valid");
122146
}

terracotta/src/main/java/com/tc/server/TCServerMain.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public static Future<Boolean> createServer(List<String> args) {
6262
public static Future<Boolean> createServer(List<String> args, OutputStream console) {
6363
try {
6464
if (Files.isDirectory(Directories.getServerLibFolder())) {
65-
Optional<Path> p = Files.list(Directories.getServerLibFolder()).filter(f->f.getFileName().toString().startsWith("tc-server")).findFirst();
66-
67-
ClassLoader serverClassLoader = new URLClassLoader(new URL[] {p.get().toUri().toURL()}, TCServerMain.class.getClassLoader());
65+
Path serverJar = Directories.getServerJar();
66+
67+
ClassLoader serverClassLoader = new URLClassLoader(new URL[] {serverJar.toUri().toURL()}, TCServerMain.class.getClassLoader());
6868

6969
return ServerFactory.createServer(args, console, serverClassLoader);
7070
}

0 commit comments

Comments
 (0)