Skip to content
This repository was archived by the owner on Nov 22, 2017. It is now read-only.

Commit fe05be7

Browse files
SolandraDaemon (Working Version)
1 parent c2dd350 commit fe05be7

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

src/solandra/SolandraDaemon.java

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package solandra;
19+
20+
import lucandra.CassandraUtils;
21+
import java.io.IOException;
22+
import org.apache.cassandra.service.CassandraDaemon;
23+
24+
/**
25+
* This class supports two methods for creating a Cassandra node daemon,
26+
* invoking the class's main method, and using the jsvc wrapper from
27+
* commons-daemon, (for more information on using this class with the
28+
* jsvc wrapper, see the
29+
* <a href="http://commons.apache.org/daemon/jsvc.html">Commons Daemon</a>
30+
* documentation).
31+
*/
32+
public class SolandraDaemon implements CassandraDaemon {
33+
34+
/**
35+
* Initialize the Cassandra Daemon based on the given <a
36+
* href="http://commons.apache.org/daemon/jsvc.html">Commons
37+
* Daemon</a>-specific arguments. To clarify, this is a hook for JSVC.
38+
*
39+
* @param arguments
40+
* the arguments passed in from JSVC
41+
* @throws IOException
42+
*/
43+
public void init(String[] arguments) throws IOException {
44+
// Nothing
45+
}
46+
47+
/**
48+
* Start the Cassandra Daemon, assuming that it has already been
49+
* initialized, via either {@link #init(String[])} or
50+
* {@link #load(String[])}.
51+
*
52+
* @throws IOException
53+
*/
54+
public void start() throws IOException {
55+
startRPCServer();
56+
}
57+
58+
/**
59+
* Stop the daemon, ideally in an idempotent manner.
60+
*/
61+
public void stop() {
62+
stopRPCServer();
63+
}
64+
65+
/**
66+
* Clean up all resources obtained during the lifetime of the daemon. Just
67+
* to clarify, this is a hook for JSVC.
68+
*/
69+
public void destroy() {
70+
// Nothing
71+
}
72+
73+
@SuppressWarnings("CallToThreadDumpStack")
74+
public void startRPCServer() {
75+
String context = System.getProperty("solandra.context", "/solandra");
76+
try {
77+
CassandraUtils.startupServer();
78+
79+
JettySolandraRunner jetty = new JettySolandraRunner(context, CassandraUtils.port, CassandraUtils.webHost);
80+
jetty.start(false);
81+
} catch (Exception ex) {
82+
ex.printStackTrace();
83+
}
84+
}
85+
86+
public void stopRPCServer() {
87+
CassandraUtils.stopServer();
88+
}
89+
90+
public boolean isRPCServerRunning() {
91+
return true;
92+
}
93+
94+
/**
95+
* A convenience method to initialize and start the daemon in one shot.
96+
*/
97+
public void activate() {
98+
startRPCServer();
99+
}
100+
101+
/**
102+
* A convenience method to stop and destroy the daemon in one shot.
103+
*/
104+
public void deactivate() {
105+
stopRPCServer();
106+
}
107+
}

0 commit comments

Comments
 (0)