All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.oracle.tools.runtime.coherence.ClusterMemberSchema Maven / Gradle / Ivy

There is a newer version: 2.0.0-RC9
Show newest version
/*
 * File: ClusterMemberSchema.java
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * The contents of this file are subject to the terms and conditions of 
 * the Common Development and Distribution License 1.0 (the "License").
 *
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the License by consulting the LICENSE.txt file
 * distributed with this file, or by consulting https://oss.oracle.com/licenses/CDDL
 *
 * 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 LICENSE.txt.
 *
 * 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]"
 */

package com.oracle.tools.runtime.coherence;

import com.oracle.tools.runtime.ApplicationConsole;

import com.oracle.tools.runtime.java.AbstractJavaApplicationSchema;
import com.oracle.tools.runtime.java.ContainerBasedJavaApplicationBuilder;
import com.oracle.tools.runtime.java.JavaApplicationBuilder;
import com.oracle.tools.runtime.java.JavaApplicationSchema;
import com.oracle.tools.runtime.java.JavaProcess;
import com.oracle.tools.runtime.java.util.CallableStaticMethod;

import com.oracle.tools.runtime.network.Constants;

import com.tangosol.coherence.component.net.Management;

import com.tangosol.net.DefaultCacheServer;

import java.util.Iterator;
import java.util.Properties;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;

/**
 * A {@link ClusterMemberSchema} is a Coherence-based specific {@link JavaApplicationSchema}.
 * 

* Copyright (c) 2013. All Rights Reserved. Oracle Corporation.
* Oracle is a registered trademark of Oracle Corporation and/or its affiliates. * * @author Brian Oliver */ public class ClusterMemberSchema extends AbstractJavaApplicationSchema implements ContainerBasedJavaApplicationBuilder.ApplicationController { /** * The {@link Management} enumeration specifies the valid JMX Management Modes for a cluster node. */ public enum JMXManagementMode { ALL, NONE, REMOTE_ONLY, LOCAL_ONLY; /** * Determines the system property representation of the {@link JMXManagementMode} * * @return A {@link String} */ public String getSystemProperty() { // default to all String result = "all"; if (this == NONE) { result = "none"; } else if (this == REMOTE_ONLY) { result = "remote-only"; } else if (this == LOCAL_ONLY) { result = "local-only"; } return result; } } /** * The tangosol.coherence.cacheconfig property. */ public static final String PROPERTY_CACHECONFIG = "tangosol.coherence.cacheconfig"; /** * The tangosol.coherence.cluster property. */ public static final String PROPERTY_CLUSTER_NAME = "tangosol.coherence.cluster"; /** * The tangosol.coherence.clusterport property. */ public static final String PROPERTY_CLUSTER_PORT = "tangosol.coherence.clusterport"; /** * The tangosol.coherence.distributed.localstorage property. */ public static final String PROPERTY_DISTRIBUTED_LOCALSTORAGE = "tangosol.coherence.distributed.localstorage"; /** * The tangosol.coherence.localhost property. */ public static final String PROPERTY_LOCALHOST_ADDRESS = "tangosol.coherence.localhost"; /** * The tangosol.coherence.log property. */ public static final String PROPERTY_LOG = "tangosol.coherence.log"; /** * The tangosol.coherence.log.level property. */ public static final String PROPERTY_LOG_LEVEL = "tangosol.coherence.log.level"; /** * The tangosol.coherence.role property. */ public static final String PROPERTY_ROLE_NAME = "tangosol.coherence.role"; /** * The tangosol.coherence.site property. */ public static final String PROPERTY_SITE_NAME = "tangosol.coherence.site"; /** * The tangosol.coherence.tcmp.enabled property. */ public static final String PROPERTY_TCMP_ENABLED = "tangosol.coherence.tcmp.enabled"; /** * The tangosol.coherence.management property. */ public static final String PROPERTY_MANAGEMENT_MODE = "tangosol.coherence.management"; /** * The tangosol.coherence.management.remote property. */ public static final String PROPERTY_MANAGEMENT_REMOTE = "tangosol.coherence.management.remote"; /** * The tangosol.coherence.ttl property. */ public static final String PROPERTY_MULTICAST_TTL = "tangosol.coherence.ttl"; /** * The tangosol.pof.config property. */ public static final String PROPERTY_POF_CONFIG = "tangosol.pof.config"; /** * The tangosol.pof.enabled property. */ public static final String PROPERTY_POF_ENABLED = "tangosol.pof.enabled"; /** * The tangosol.coherence.wka property. */ public static final String PROPERTY_WELL_KNOWN_ADDRESS = "tangosol.coherence.wka"; /** * The tangosol.coherence.wka.port property. */ public static final String PROPERTY_WELL_KNOWN_ADDRESS_PORT = "tangosol.coherence.wka.port"; /** * The com.tangosol.net.DefaultCacheServer classname. */ public static final String DEFAULT_CACHE_SERVER_CLASSNAME = "com.tangosol.net.DefaultCacheServer"; /** * Constructs a {@link ClusterMemberSchema} for the {@link DefaultCacheServer} * defaulting to use the current classpath. */ public ClusterMemberSchema() { this(DEFAULT_CACHE_SERVER_CLASSNAME); } /** * Constructs a {@link ClusterMemberSchema} defaulting to use the current classpath * * @param applicationClassName The name of the class for the Coherence-based application. */ public ClusterMemberSchema(String applicationClassName) { super(applicationClassName); } /** * Constructs a {@link ClusterMemberSchema}. * * @param applicationClassName The name of the class for the Coherence-based application. * @param classPath The class path of the application. */ public ClusterMemberSchema(String applicationClassName, String classPath) { super(applicationClassName, classPath); } /** * {@inheritDoc} */ @Override protected void configureDefaults() { setPreferIPv4(true); // the following is to ensure Coherence will work with Java 1.8.0 b91 setSystemProperty("javax.xml.accessExternalSchema", "file"); // ensure we're running in headless mode setHeadless(true); } /** * Sets the Cache Configuration URI for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param cacheConfigURI * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setCacheConfigURI(String cacheConfigURI) { setSystemProperty(PROPERTY_CACHECONFIG, cacheConfigURI); return this; } /** * Sets if storage should be enabled for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param isStorageEnabled * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setStorageEnabled(boolean isStorageEnabled) { setSystemProperty(PROPERTY_DISTRIBUTED_LOCALSTORAGE, isStorageEnabled); return this; } /** * Sets if TCMP should be enabled for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param isTCMPEnabled * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setTCMPEnabled(boolean isTCMPEnabled) { setSystemProperty(PROPERTY_TCMP_ENABLED, isTCMPEnabled); return this; } /** * Sets the cluster port for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param port * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setClusterPort(int port) { setSystemProperty(PROPERTY_CLUSTER_PORT, port); return this; } /** * Sets the cluster port for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param portIterator * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setClusterPort(Iterator portIterator) { setSystemProperty(PROPERTY_CLUSTER_PORT, portIterator); return this; } /** * Sets the cluster name for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param name * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setClusterName(String name) { setSystemProperty(PROPERTY_CLUSTER_NAME, name); return this; } /** * Sets the role name for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param name * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setRoleName(String name) { setSystemProperty(PROPERTY_ROLE_NAME, name); return this; } /** * Sets the site name for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param name * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setSiteName(String name) { setSystemProperty(PROPERTY_SITE_NAME, name); return this; } /** * Sets the multicast time-to-live for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param ttl * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setMulticastTTL(int ttl) { setSystemProperty(PROPERTY_MULTICAST_TTL, ttl); return this; } /** * Sets the JMX management mode for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param mode * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setJMXManagementMode(JMXManagementMode mode) { setJMXSupport((mode == JMXManagementMode.ALL || mode == JMXManagementMode.LOCAL_ONLY)); setSystemProperty(PROPERTY_MANAGEMENT_MODE, mode.getSystemProperty()); return this; } /** * Sets if remote JMX monitoring is enabled for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param enabled * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setRemoteJMXManagement(boolean enabled) { setJMXSupport(enabled); setSystemProperty(PROPERTY_MANAGEMENT_REMOTE, enabled); return this; } /** * Sets the localhost address for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param localHostAddress * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setLocalHostAddress(String localHostAddress) { setSystemProperty(PROPERTY_LOCALHOST_ADDRESS, localHostAddress); return this; } /** * Sets the log level for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param level * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setLogLevel(int level) { setSystemProperty(PROPERTY_LOG_LEVEL, level); return this; } /** * Sets the log for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. *

* Log destinations typically include: "jdk", "log4j", "stdout", "stderr" or * a file name. * * @param destination the destination for logs * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setLog(String destination) { setSystemProperty(PROPERTY_LOG, destination); return this; } /** * Sets POF configuration uri for {@link ClusterMember}s created with this {@link ClusterMemberSchema}. * * @param pofConfigURI * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setPofConfigURI(String pofConfigURI) { setSystemProperty(PROPERTY_POF_CONFIG, pofConfigURI); setPofEnabled(true); return this; } /** * Configures the resulting {@link ClusterMember} to be Portable-Object-Format serialization enabled. * * @param isEnabled true for POF enabled, false otherwise. * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setPofEnabled(boolean isEnabled) { setSystemProperty(PROPERTY_POF_ENABLED, isEnabled); return this; } /** * Configures the {@link ClusterMemberSchema} so that when realized by a {@link JavaApplicationBuilder} * the resulting {@link ClusterMember} will be running locally in single-server mode. * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setSingleServerMode() { setLocalHostAddress(Constants.getLocalHost()); setMulticastTTL(0); return this; } /** * Sets the Coherence Well Known Address (WKA). * * @param address The address (as a {@link String}). * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setWellKnownAddress(String address) { return setSystemProperty(PROPERTY_WELL_KNOWN_ADDRESS, address); } /** * Sets the Coherence Well Known Address (WKA) Port * * @param port The port * * @return The {@link ClusterMemberSchema}. */ public ClusterMemberSchema setWellKnownAddressPort(int port) { return setSystemProperty(PROPERTY_WELL_KNOWN_ADDRESS_PORT, port); } /** * {@inheritDoc} */ @Override public ClusterMember createJavaApplication(JavaProcess process, String name, ApplicationConsole console, Properties environmentVariables, Properties systemProperties) { return new ClusterMember(process, name, console, environmentVariables, systemProperties, isDiagnosticsEnabled(), getDefaultTimeout(), getDefaultTimeoutUnits(), getLifecycleInterceptors()); } /** * {@inheritDoc} */ @Override public Future start(ContainerBasedJavaApplicationBuilder.ControllableApplication application) { Callable callable = new CallableStaticMethod("com.tangosol.net.DefaultCacheServer", "startDaemon"); Future future = application.submit(callable); return future; } /** * {@inheritDoc} */ @Override public Future destroy(ContainerBasedJavaApplicationBuilder.ControllableApplication application) { Callable callable = new CallableStaticMethod("com.tangosol.net.DefaultCacheServer", "shutdown"); Future future = application.submit(callable); return future; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy