nstream.adapter.runtime.AppPlane Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nstream-adapter-runtime Show documentation
Show all versions of nstream-adapter-runtime Show documentation
Generic Plane and Agent to be used to wire the different Patches
// Copyright 2015-2024 Nstream, inc.
//
// Licensed under the Redis Source Available License 2.0 (RSALv2) Agreement;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://redis.com/legal/rsalv2-agreement/
//
// 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.
// See the License for the specific language governing permissions and
// limitations under the License.
package nstream.adapter.runtime;
import java.io.IOException;
import nstream.adapter.common.LabeledLog;
import nstream.adapter.common.provision.ProvisionLoader;
import swim.api.plane.AbstractPlane;
import swim.kernel.Kernel;
import swim.kernel.KernelLoader;
import swim.server.ServerLoader;
import swim.structure.Value;
import swim.util.Log;
public class AppPlane extends AbstractPlane {
private static final Log DEFAULT_LOG = LabeledLog.forUniform("AppPlane#main", System.out::println);
public AppPlane() {
}
private static Value kernelConfig() {
final ClassLoader classLoader = AppPlane.class.getClassLoader();
try {
Value kernelConfig = KernelLoader.loadConfig(classLoader);
if (kernelConfig == null) {
kernelConfig = KernelLoader.loadConfigResource(classLoader, "server.recon");
}
if (kernelConfig == null) {
kernelConfig = Value.absent();
}
return kernelConfig;
} catch (IOException e) {
throw new RuntimeException("Failed to load kernel config", e);
}
}
public static void main(String[] args) {
// Load resources that may be required by the Swim plane, as configured by
// the server configuration file.
final int provisionLoadErrors = ProvisionLoader.loadProvisions(DEFAULT_LOG, kernelConfig());
if (provisionLoadErrors > 0) {
DEFAULT_LOG.error(provisionLoadErrors + " Provisions did not load correctly; will not initialize Swim server");
System.exit(-1);
}
ProvisionLoader.logProvisionNames(DEFAULT_LOG);
// Load the SwimOS kernel, loading its configuration from the
// `server.recon` Java resource.
final Kernel kernel = ServerLoader.loadServer();
// Boot the SwimOS kernel.
kernel.start();
System.out.println("Running AppPlane ...");
// Park the main thread while the application concurrently runs.
kernel.run();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy