com.gemstone.gemfire.admin.internal.CacheServerImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.admin.internal;
import com.gemstone.gemfire.admin.*;
import com.gemstone.gemfire.distributed.internal.DM;
import com.gemstone.gemfire.distributed.internal.DistributionManager;
import com.gemstone.gemfire.internal.admin.GemFireVM;
import com.gemstone.gemfire.internal.admin.remote.RemoteApplicationVM;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
/**
* Implements the administrative interface to a cache server.
*
* @author David Whitlock
* @since 3.5
*/
public class CacheServerImpl extends ManagedSystemMemberImpl
implements CacheVm, CacheServer {
private static final String GFXD_LAUNCHER_NAME = "gfxd";
private static final String GFE_LAUNCHER_NAME = "cacheserver";
private static final boolean isSqlFire = Boolean.getBoolean("isSqlFire");
/** How many new CacheServer
s have been created? */
private static int newCacheServers = 0;
/////////////////////// Instance Fields ///////////////////////
/** The configuration object for this cache server */
private final CacheServerConfigImpl config;
///////////////////////// Constructors ////////////////////////
/**
* Creates a new CacheServerImpl
that represents a
* non-existsing (unstarted) cache server in a given distributed
* system.
*/
public CacheServerImpl(AdminDistributedSystemImpl system,
CacheVmConfig config)
throws AdminException {
super(system, config);
this.config = (CacheServerConfigImpl) config;
this.config.setManagedEntity(this);
}
/**
* Creates a new CacheServerImpl
that represents an
* existing dedicated cache server in a given distributed system.
*/
public CacheServerImpl(AdminDistributedSystemImpl system,
GemFireVM vm)
throws AdminException {
super(system, vm);
this.config = new CacheServerConfigImpl(vm);
}
////////////////////// Instance Methods //////////////////////
@Override
public SystemMemberType getType() {
return SystemMemberType.CACHE_VM;
}
public String getNewId() {
synchronized (CacheServerImpl.class) {
return "CacheVm" + (++newCacheServers);
}
}
public void start() throws AdminException {
if (!needToStart()) {
return;
}
this.config.validate();
this.controller.start(this);
this.config.setManagedEntity(this);
}
public void stop() {
if (!needToStop()) {
return;
}
this.controller.stop(this);
// NOTE: DistributedSystem nodeLeft will then set this.manager to null
this.config.setManagedEntity(null);
}
public boolean isRunning() {
DM dm = ((AdminDistributedSystemImpl)getDistributedSystem()).getDistributionManager();
if(dm == null) {
try {
return this.controller.isRunning(this);
}
catch (IllegalStateException e) {
return false;
}
}
return ((DistributionManager)dm).getDistributionManagerIdsIncludingAdmin().contains(getDistributedMember());
}
public CacheServerConfig getConfig() {
return this.config;
}
public CacheVmConfig getVmConfig() {
return this.config;
}
//////////////////////// Command execution ////////////////////////
public ManagedEntityConfig getEntityConfig() {
return this.getConfig();
}
public String getEntityType() {
// Fix bug 32564
return "Cache Vm";
}
public String getStartCommand() {
StringBuffer sb = new StringBuffer();
if (!isSqlFire) {
sb.append(this.controller.getProductExecutable(this, GFE_LAUNCHER_NAME));
sb.append(" start -dir=");
} else {
sb.append(this.controller.getProductExecutable(this, GFXD_LAUNCHER_NAME));
sb.append(" server start -dir=");
}
sb.append(this.getConfig().getWorkingDirectory());
String file = this.getConfig().getCacheXMLFile();
if (file != null && file.length() > 0) {
sb.append(" ");
sb.append(com.gemstone.gemfire.distributed.internal.DistributionConfig.CACHE_XML_FILE_NAME);
sb.append("=");
sb.append(file);
}
String classpath = this.getConfig().getClassPath();
if (classpath != null && classpath.length() > 0) {
sb.append(" -classpath=");
sb.append(classpath);
}
appendConfiguration(sb);
return sb.toString().trim();
}
public String getStopCommand() {
StringBuffer sb = new StringBuffer();
if (!isSqlFire) {
sb.append(this.controller.getProductExecutable(this, GFE_LAUNCHER_NAME));
sb.append(" stop -dir=");
} else {
sb.append(this.controller.getProductExecutable(this, GFXD_LAUNCHER_NAME));
sb.append(" server stop -dir=");
}
sb.append(this.getConfig().getWorkingDirectory());
return sb.toString().trim();
}
public String getIsRunningCommand() {
StringBuffer sb = new StringBuffer();
if (!isSqlFire) {
sb.append(this.controller.getProductExecutable(this, GFE_LAUNCHER_NAME));
sb.append(" status -dir=");
} else {
sb.append(this.controller.getProductExecutable(this, GFXD_LAUNCHER_NAME));
sb.append(" server status -dir=");
}
sb.append(this.getConfig().getWorkingDirectory());
return sb.toString().trim();
}
/**
* Find whether this server is primary for given client (durableClientId)
*
* @param durableClientId -
* durable-id of the client
* @return true if the server is primary for given client
*
* @since 5.6
*/
public boolean isPrimaryForDurableClient(String durableClientId)
{
RemoteApplicationVM vm = (RemoteApplicationVM)this.getGemFireVM();
boolean isPrimary = false;
if (vm != null) {
isPrimary = vm.isPrimaryForDurableClient(durableClientId);
}
return isPrimary;
}
}