http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberBridgeServerImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberBridgeServerImpl.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberBridgeServerImpl.java new file mode 100644 index 0000000..48f432f --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberBridgeServerImpl.java @@ -0,0 +1,233 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.impl; + +import java.io.Serializable; + +import org.apache.geode.InternalGemFireException; +import org.apache.geode.internal.admin.api.AdminException; +import org.apache.geode.internal.admin.api.SystemMemberBridgeServer; +import org.apache.geode.internal.admin.api.SystemMemberCacheServer; +import org.apache.geode.cache.server.ServerLoadProbe; +import org.apache.geode.internal.admin.*; +import org.apache.geode.internal.i18n.LocalizedStrings; + +/** + * Implementation of an object used for managing cache servers. + * + * @since GemFire 4.0 + */ +public class SystemMemberBridgeServerImpl + implements SystemMemberCacheServer, SystemMemberBridgeServer { + + /** The VM in which the bridge server resides */ + private final GemFireVM vm; + + /** The cache server by this bridge server */ + private CacheInfo cache; + + /** Information about the bridge server */ + private AdminBridgeServer bridgeInfo; + + ///////////////////// Constructors ///////////////////// + + /** + * Creates a new <code>SystemMemberBridgeServerImpl</code> that + * administers the given bridge server in the given VM. + */ + protected SystemMemberBridgeServerImpl(SystemMemberCacheImpl cache, + AdminBridgeServer bridgeInfo) + + throws AdminException { + + this.vm = cache.getVM(); + this.cache = cache.getCacheInfo(); + this.bridgeInfo = bridgeInfo; + } + + //////////////////// Instance Methods //////////////////// + + /** + * Throws an <code>AdminException</code> if this bridge server is + * running. + */ + private void checkRunning() throws AdminException { + if (this.isRunning()) { + throw new AdminException(LocalizedStrings.SystemMemberBridgeServerImpl_CANNOT_CHANGE_THE_CONFIGURATION_OF_A_RUNNING_BRIDGE_SERVER.toLocalizedString()); + } + } + + public int getPort() { + return this.bridgeInfo.getPort(); + } + + public void setPort(int port) throws AdminException { + checkRunning(); + this.bridgeInfo.setPort(port); + } + + public void start() throws AdminException { + this.vm.startBridgeServer(this.cache, this.bridgeInfo); + } + + public boolean isRunning() { + return this.bridgeInfo.isRunning(); + } + + public void stop() throws AdminException { + this.vm.stopBridgeServer(this.cache, this.bridgeInfo); + } + + /** + * Returns the VM-unique id of this bridge server + */ + protected int getBridgeId() { + return this.bridgeInfo.getId(); + } + + public void refresh() { + try { + this.bridgeInfo = + this.vm.getBridgeInfo(this.cache, this.bridgeInfo.getId()); + + } catch (AdminException ex) { + throw new InternalGemFireException(LocalizedStrings.SystemMemberBridgeServerImpl_UNEXPECTED_EXCEPTION_WHILE_REFRESHING.toLocalizedString(), ex); + } + } + + public String getBindAddress() { + return this.bridgeInfo.getBindAddress(); + } + + public void setBindAddress(String address) throws AdminException { + checkRunning(); + this.bridgeInfo.setBindAddress(address); + } + + public String getHostnameForClients() { + return this.bridgeInfo.getHostnameForClients(); + } + + public void setHostnameForClients(String name) throws AdminException { + checkRunning(); + this.bridgeInfo.setHostnameForClients(name); + } + + public void setNotifyBySubscription(boolean b) throws AdminException { + checkRunning(); + this.bridgeInfo.setNotifyBySubscription(b); + } + + public boolean getNotifyBySubscription() { + return this.bridgeInfo.getNotifyBySubscription(); + } + + public void setSocketBufferSize(int socketBufferSize) throws AdminException { + checkRunning(); + this.bridgeInfo.setSocketBufferSize(socketBufferSize); + } + + public int getSocketBufferSize() { + return this.bridgeInfo.getSocketBufferSize(); + } + + public void setTcpDelay(boolean setting) throws AdminException { + checkRunning(); + this.bridgeInfo.setTcpNoDelay(setting); + } + + public boolean getTcpDelay() { + return this.bridgeInfo.getTcpNoDelay(); + } + + public void setMaximumTimeBetweenPings(int maximumTimeBetweenPings) throws AdminException { + checkRunning(); + this.bridgeInfo.setMaximumTimeBetweenPings(maximumTimeBetweenPings); + } + + public int getMaximumTimeBetweenPings() { + return this.bridgeInfo.getMaximumTimeBetweenPings(); + } + + public int getMaxConnections() { + return this.bridgeInfo.getMaxConnections(); + } + + public void setMaxConnections(int maxCons) throws AdminException { + checkRunning(); + this.bridgeInfo.setMaxConnections(maxCons); + } + + public int getMaxThreads() { + return this.bridgeInfo.getMaxThreads(); + } + + public void setMaxThreads(int maxThreads) throws AdminException { + checkRunning(); + this.bridgeInfo.setMaxThreads(maxThreads); + } + + public int getMaximumMessageCount() { + return this.bridgeInfo.getMaximumMessageCount(); + } + + public void setMaximumMessageCount(int maxMessageCount) throws AdminException { + checkRunning(); + this.bridgeInfo.setMaximumMessageCount(maxMessageCount); + } + + public int getMessageTimeToLive() { + return this.bridgeInfo.getMessageTimeToLive(); + } + + public void setMessageTimeToLive(int messageTimeToLive) throws AdminException { + checkRunning(); + this.bridgeInfo.setMessageTimeToLive(messageTimeToLive); + } + + public void setGroups(String[] groups) throws AdminException { + checkRunning(); + this.bridgeInfo.setGroups(groups); + } + + public String[] getGroups() { + return this.bridgeInfo.getGroups(); + } + + public String getLoadProbe() { + return this.bridgeInfo.getLoadProbe().toString(); + } + + public void setLoadProbe(ServerLoadProbe loadProbe) throws AdminException { + checkRunning(); + if(!(loadProbe instanceof Serializable)) { + throw new IllegalArgumentException("Load probe must be Serializable to be used with admin API"); + } + this.bridgeInfo.setLoadProbe(loadProbe); + } + + public long getLoadPollInterval() { + return this.bridgeInfo.getLoadPollInterval(); + } + + public void setLoadPollInterval(long loadPollInterval) throws AdminException { + checkRunning(); + this.bridgeInfo.setLoadPollInterval(loadPollInterval); + } + + +}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheEventImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheEventImpl.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheEventImpl.java new file mode 100644 index 0000000..a99e8d3 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheEventImpl.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.impl; + +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.cache.Operation; +import org.apache.geode.internal.admin.api.SystemMemberCacheEvent; +import org.apache.geode.internal.admin.api.SystemMemberCacheListener; + +/** + * An event that describes an operation on a cache. + * Instances of this are delivered to a {@link SystemMemberCacheListener} when a + * a cache is created or closed. + * + * @since GemFire 5.0 + */ +public class SystemMemberCacheEventImpl + extends SystemMembershipEventImpl + implements SystemMemberCacheEvent +{ + + /** The operation done by this event */ + private Operation op; + + /////////////////////// Constructors /////////////////////// + + /** + * Creates a new <code>SystemMemberCacheEvent</code> for the member + * with the given id. + */ + protected SystemMemberCacheEventImpl(DistributedMember id, Operation op) { + super(id); + this.op = op; + } + + ///////////////////// Instance Methods ///////////////////// + + public Operation getOperation() { + return this.op; + } + + @Override + public String toString() { + return super.toString() + " op=" + this.op; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheEventProcessor.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheEventProcessor.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheEventProcessor.java new file mode 100644 index 0000000..56c179d --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheEventProcessor.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.impl; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.apache.logging.log4j.Logger; + +import org.apache.geode.DataSerializer; +import org.apache.geode.internal.admin.api.SystemMemberCacheEvent; +import org.apache.geode.internal.admin.api.SystemMemberCacheListener; +import org.apache.geode.internal.admin.api.SystemMemberRegionEvent; +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.Operation; +import org.apache.geode.cache.Region; +import org.apache.geode.distributed.internal.DistributionManager; +import org.apache.geode.distributed.internal.HighPriorityDistributionMessage; +import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.internal.logging.LogService; + +/** + * This class processes the message to be delivered to admin node. + * [This needs to be redesigned and reimplemented... see 32887] + * @since GemFire 5.0 + */ +public class SystemMemberCacheEventProcessor { + private static final Logger logger = LogService.getLogger(); + + + /* + * Sends cache create/close message to Admin VMs + */ + public static void send(Cache c, Operation op) { + send(c, null, op); + } + + /* + * Sends region creation/destroy message to Admin VMs + */ + public static void send(Cache c, Region region, Operation op) { + InternalDistributedSystem system = (InternalDistributedSystem)c.getDistributedSystem(); + Set recps = system.getDistributionManager().getAdminMemberSet(); + // @todo darrel: find out if any of these guys have region listeners + if (recps.isEmpty()) { + return; + } + SystemMemberCacheMessage msg = new SystemMemberCacheMessage(); + if (region == null) { + msg.regionPath = null; + } else { + msg.regionPath = region.getFullPath(); + } + msg.setRecipients(recps); + msg.op = op; + system.getDistributionManager().putOutgoing(msg); + } + + + public static final class SystemMemberCacheMessage extends HighPriorityDistributionMessage + { + protected String regionPath; + protected Operation op; + + @Override + protected void process(DistributionManager dm) { + AdminDistributedSystemImpl admin = AdminDistributedSystemImpl.getConnectedInstance(); + if (admin == null) { + if (logger.isDebugEnabled()) { + logger.debug("Ignoring message because there is no admin distributed system present: {}", this); + } + return; // probably shutting down or still connecting + } + List listeners = admin.getCacheListeners(); + Iterator itr = listeners.iterator(); + SystemMemberCacheListener listener = null; + while(itr.hasNext()){ + listener = (SystemMemberCacheListener)itr.next(); + if (this.regionPath == null) { + SystemMemberCacheEvent event = new SystemMemberCacheEventImpl(getSender(), this.op); + if (this.op == Operation.CACHE_CREATE) { + listener.afterCacheCreate(event); + } else { + listener.afterCacheClose(event); + } + } else { + SystemMemberRegionEvent event = new SystemMemberRegionEventImpl(getSender(), this.op, this.regionPath); + if (this.op.isRegionDestroy()) { + listener.afterRegionLoss(event); + } else { + listener.afterRegionCreate(event); + } + } + } + } + + public int getDSFID() { + return ADMIN_CACHE_EVENT_MESSAGE; + } + + @Override + public void fromData(DataInput in) + throws IOException, ClassNotFoundException { + super.fromData(in); + this.regionPath = DataSerializer.readString(in); + this.op = Operation.fromOrdinal(in.readByte()); + } + + @Override + public void toData(DataOutput out) throws IOException { + super.toData(out); + DataSerializer.writeString(this.regionPath, out); + out.writeByte(this.op.ordinal); + } + + @Override + public String toString() { + StringBuffer buff = new StringBuffer(); + buff.append("SystemMemberCacheMessage (region='"); + buff.append(this.regionPath); + buff.append("'; sender="); + buff.append(this.sender); + buff.append("; op="); + buff.append(this.op); + buff.append(")"); + return buff.toString(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheImpl.java new file mode 100644 index 0000000..ac6ab4c --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberCacheImpl.java @@ -0,0 +1,320 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.impl; + +import org.apache.geode.cache.*; +import org.apache.geode.internal.Assert; +import org.apache.geode.internal.ObjIdMap; +import org.apache.geode.internal.admin.*; +import org.apache.geode.internal.admin.api.AdminException; +import org.apache.geode.internal.admin.api.CacheDoesNotExistException; +import org.apache.geode.internal.admin.api.GemFireMemberStatus; +import org.apache.geode.internal.admin.api.RegionSubRegionSnapshot; +import org.apache.geode.internal.admin.api.Statistic; +import org.apache.geode.internal.admin.api.SystemMemberBridgeServer; +import org.apache.geode.internal.admin.api.SystemMemberCache; +import org.apache.geode.internal.admin.api.SystemMemberCacheServer; +import org.apache.geode.internal.admin.api.SystemMemberRegion; +import org.apache.geode.internal.i18n.LocalizedStrings; + +import java.util.*; + +/** + * View of a GemFire system member's cache. + * + * @since GemFire 3.5 + */ +public class SystemMemberCacheImpl implements SystemMemberCache { + protected final GemFireVM vm; + protected CacheInfo info; + protected Statistic[] statistics; + + /** Maps the id of a bridge server to its SystemMemberBridgeServer */ + private ObjIdMap bridgeServers = new ObjIdMap(); + + // constructors + public SystemMemberCacheImpl(GemFireVM vm) + throws CacheDoesNotExistException + { + this.vm = vm; + this.info = vm.getCacheInfo(); + if (this.info == null) { + throw new CacheDoesNotExistException(LocalizedStrings.SystemMemberCacheImpl_THE_VM_0_DOES_NOT_CURRENTLY_HAVE_A_CACHE.toLocalizedString(vm.getId())); + } + initStats(); + } + + // attributes + /** + * The name of the cache. + */ + public String getName() { + String result = this.info.getName(); + if (result == null || result.length() == 0) { + result = "default"; + } + return result; + } + /** + * Value that uniquely identifies an instance of a cache for a given member. + */ + public int getId() { + return this.info.getId(); + } + + public boolean isClosed() { + return this.info.isClosed(); + } + public int getLockTimeout() { + return this.info.getLockTimeout(); + } + public void setLockTimeout(int seconds) throws AdminException { + this.info = this.vm.setCacheLockTimeout(this.info, seconds); + } + public int getLockLease() { + return this.info.getLockLease(); + } + public void setLockLease(int seconds) throws AdminException { + this.info = this.vm.setCacheLockLease(this.info, seconds); + } + public int getSearchTimeout() { + return this.info.getSearchTimeout(); + } + public void setSearchTimeout(int seconds) throws AdminException { + this.info = this.vm.setCacheSearchTimeout(this.info, seconds); + } + public int getUpTime() { + return this.info.getUpTime(); + } + public java.util.Set getRootRegionNames() { + Set set = this.info.getRootRegionNames(); + if (set == null) { + set = Collections.EMPTY_SET; + } + return set; + } + // operations + + public void refresh() { + if (!this.info.isClosed()) { + CacheInfo cur = vm.getCacheInfo(); + if (cur == null || (this.info.getId() != cur.getId())) { + // it is a different instance of the cache. So set our version + // to closed + this.info.setClosed(); + } else { + this.info = cur; + updateStats(); + } + } + } + + public GemFireMemberStatus getSnapshot() + { + //System.out.println(">>>SystemMemberCacheJmxImpl::getSnapshot:pre::: " + this.vm); + GemFireMemberStatus stat = this.vm.getSnapshot(); + //System.out.println(">>>SystemMemberCacheJmxImpl::getSnapshot:post::: " + stat); + return stat; + } + + public RegionSubRegionSnapshot getRegionSnapshot() + { + //System.out.println(">>>SystemMemberCacheJmxImpl::getRegionSnapshot:pre::: " + this.vm); + RegionSubRegionSnapshot snap = this.vm.getRegionSnapshot(); + //System.out.println(">>>SystemMemberCacheJmxImpl::getRegionSnapshot:post::: " + snap); + return snap; + } + + public Statistic[] getStatistics() { + return this.statistics; + } + + public SystemMemberRegion getRegion(String path) + throws AdminException + { + Region r = this.vm.getRegion(this.info, path); + if (r == null) { + return null; + } else { + return createSystemMemberRegion(r); + } + } + + public SystemMemberRegion createRegion(String name, + RegionAttributes attrs) + throws AdminException + { + Region r = this.vm.createVMRootRegion(this.info, name, attrs); + if (r == null) { + return null; + + } else { + return createSystemMemberRegion(r); + } + } + + public SystemMemberRegion createVMRegion(String name, + RegionAttributes attrs) + throws AdminException + { + return createRegion(name, attrs); + } + + + // internal methods + private void initStats() { + StatResource resource = this.info.getPerfStats(); + if (resource == null) { + // See bug 31397 + Assert.assertTrue(this.isClosed()); + return; + } + + Stat[] stats = resource.getStats(); + if (stats == null || stats.length < 1) { + this.statistics = new Statistic[0]; + return; + } + + // define new statistics instances... + List statList = new ArrayList(); + for (int i = 0; i < stats.length; i++) { + statList.add(createStatistic(stats[i])); + } + this.statistics = (Statistic[]) statList.toArray(new Statistic[statList.size()]); + } + private void updateStats() { + StatResource resource = this.info.getPerfStats(); + if (resource == null) { + // See bug 31397 + Assert.assertTrue(this.isClosed()); + return; + } + + Stat[] stats = resource.getStats(); + if (stats == null || stats.length < 1) { + return; + } + + for (int i = 0; i < stats.length; i++) { + updateStatistic(stats[i]); + } + } + + private void updateStatistic(Stat stat) { + for (int i = 0; i < this.statistics.length; i++) { + if (this.statistics[i].getName().equals(stat.getName())) { + ((StatisticImpl)this.statistics[i]).setStat(stat); + return; + } + } + Assert.assertTrue(false, "Unknown stat: " + stat.getName()); + } + + /** + * Returns the <code>CacheInfo</code> that describes this cache. + * Note that this operation does not {@link #refresh} the + * <code>CacheInfo</code>. + */ + public CacheInfo getCacheInfo() { + return this.info; + } + + public GemFireVM getVM() { + return this.vm; + } + + protected Statistic createStatistic(Stat stat) { + return new StatisticImpl(stat); + } + protected SystemMemberRegion createSystemMemberRegion(Region r) + throws AdminException + { + SystemMemberRegionImpl sysMemberRegion = new SystemMemberRegionImpl(this, r); + sysMemberRegion.refresh(); + return sysMemberRegion; + } + + public SystemMemberCacheServer addCacheServer() + throws AdminException { + + AdminBridgeServer bridge = this.vm.addCacheServer(this.info); + SystemMemberCacheServer admin = + createSystemMemberBridgeServer(bridge); + bridgeServers.put(bridge.getId(), admin); + return admin; + } + + private Collection getCacheServersCollection() + throws AdminException { + Collection bridges = new ArrayList(); + + int[] bridgeIds = this.info.getBridgeServerIds(); + for (int i = 0; i < bridgeIds.length; i++) { + int id = bridgeIds[i]; + SystemMemberBridgeServer bridge = + (SystemMemberBridgeServer) bridgeServers.get(id); + if (bridge == null) { + AdminBridgeServer info = this.vm.getBridgeInfo(this.info, id); + if (info != null) { + bridge = createSystemMemberBridgeServer(info); + bridgeServers.put(info.getId(), bridge); + } + } + + if (bridge != null) { + bridges.add(bridge); + } + } + return bridges; + } + + public SystemMemberCacheServer[] getCacheServers() + throws AdminException { + Collection bridges = getCacheServersCollection(); + SystemMemberCacheServer[] array = + new SystemMemberCacheServer[bridges.size()]; + return (SystemMemberCacheServer[]) bridges.toArray(array); + }; + + /** + * Creates a new instance of <Code>SystemMemberBridgeServer</code> + * with the given configuration. + */ + protected SystemMemberBridgeServerImpl + createSystemMemberBridgeServer(AdminBridgeServer bridge) + throws AdminException { + + return new SystemMemberBridgeServerImpl(this, bridge); + } + + public boolean isServer() throws AdminException { + return this.info.isServer(); + } + + + /** + * Returns a string representation of the object. + * + * @return a string representation of the object + */ + @Override + public String toString() { + return getName(); + } +} + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberImpl.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberImpl.java new file mode 100755 index 0000000..8daf7c9 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberImpl.java @@ -0,0 +1,512 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.impl; + +import org.apache.geode.CancelException; +import org.apache.geode.SystemFailure; +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.distributed.Role; +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.distributed.internal.DistributionConfigImpl; +import org.apache.geode.distributed.internal.membership.InternalDistributedMember; +import org.apache.geode.internal.Config; +import org.apache.geode.internal.ConfigSource; +import org.apache.geode.internal.admin.GemFireVM; +import org.apache.geode.internal.admin.StatResource; +import org.apache.geode.internal.admin.api.AdminDistributedSystem; +import org.apache.geode.internal.admin.api.AdminException; +import org.apache.geode.internal.admin.api.CacheDoesNotExistException; +import org.apache.geode.internal.admin.api.ConfigurationParameter; +import org.apache.geode.internal.admin.api.RuntimeAdminException; +import org.apache.geode.internal.admin.api.StatisticResource; +import org.apache.geode.internal.admin.api.SystemMember; +import org.apache.geode.internal.admin.api.SystemMemberCache; +import org.apache.geode.internal.admin.api.SystemMemberType; +import org.apache.geode.internal.i18n.LocalizedStrings; +import org.apache.geode.internal.logging.LogService; +import org.apache.logging.log4j.Logger; + +import java.net.InetAddress; +import java.util.*; + +/** + * Member of a GemFire system. + * + * @since GemFire 3.5 + */ +public class SystemMemberImpl +implements SystemMember, ConfigurationParameterListener { + + private static final Logger logger = LogService.getLogger(); + + /** Identifying name of this member. + * Note that by default this is the string form of internalId but the + * ManagedSystemMemberImpl subclass resets it to getNewId() + */ + protected String id; + + /** Unique internal id that the system impl identifies this member with */ + protected InternalDistributedMember internalId; + + /** The name of this system member */ + protected String name; + + /** Host name of the machine this member resides on */ + protected String host; + + /** The internal configuration this impl delegates to for runtime config */ +// private Config config; + + /** The configuration parameters for this member. Maps the name of + the ConfigurationParameter to the ConfigurationParameter. */ + protected Map parms = new HashMap(); + + /** The {@link AdminDistributedSystem} this is a member of */ + protected AdminDistributedSystem system; + + /** Internal GemFire vm to delegate to */ + private GemFireVM vm; + + // ------------------------------------------------------------------------- + // Constructor(s) + // ------------------------------------------------------------------------- + + /** + * Constructs new <code>SystemMemberImpl</code> for a + * <code>ManagedEntity</code> that has yet to be started. + * + * @param system the distributed system this member belongs to + */ + protected SystemMemberImpl(AdminDistributedSystem system) + throws AdminException { + + this.system = system; + refreshConfig(getDefaultConfig()); + } + + /** + * Constructs new <code>SystemMemberImpl</code> from the given + * <code>GemFireVM</code>. This constructor is invoked when we + * discover a new member of the distributed system. + * + * @param system the distributed system this member belongs to + * @param vm internal GemFire vm to delegate to + */ + public SystemMemberImpl(AdminDistributedSystem system, + GemFireVM vm) + throws AdminException { + + this(system); + setGemFireVM(vm); + } + + /** + * Constructs the instance of SystemMember using the corresponding + * InternalDistributedMember instance of a DS member for the given + * AdminDistributedSystem. + * + * @param system + * Current AdminDistributedSystem instance + * @param member + * InternalDistributedMember instance for which a SystemMember + * instance is to be constructed. + * @throws AdminException + * if construction of SystemMember fails + * + * @since GemFire 6.5 + */ + protected SystemMemberImpl(AdminDistributedSystem system, + InternalDistributedMember member) + throws AdminException { + this(system); + updateByInternalDistributedMember(member); + } + + // ------------------------------------------------------------------------- + // Attribute accessors and mutators + // ------------------------------------------------------------------------- + + /** + * Returns a <code>Config</code> object with the appropriate default + * values for a newly-created system member. + */ + protected Config getDefaultConfig() { + Properties props = new Properties(); + return new DistributionConfigImpl(props); + } + + public final AdminDistributedSystem getDistributedSystem() { + return this.system; + } + + public final InternalDistributedMember getInternalId() { + return internalId; + } + + public final String getId() { + return this.id; + } + + public final String getName() { + return this.name; + } + + public String getHost() { + return this.host; + } + + public final InetAddress getHostAddress() { + return InetAddressUtil.toInetAddress(this.getHost()); + } + + // ------------------------------------------------------------------------- + // Operations + // ------------------------------------------------------------------------- + + public final String getLog() { + String childTail = null; + String mainTail = null; + GemFireVM vm = getGemFireVM(); + if (vm != null) { + String[] log = vm.getSystemLogs(); + if (log != null && log.length > 0) mainTail = log[0]; + if (log != null && log.length > 1) childTail = log[1]; + } + + if (childTail == null && mainTail == null) { + return LocalizedStrings.SystemMemberImpl_NO_LOG_FILE_CONFIGURED_LOG_MESSAGES_WILL_BE_DIRECTED_TO_STDOUT.toLocalizedString(); + } + else { + StringBuffer result = new StringBuffer(); + if (mainTail != null) { + result.append(mainTail); + } + if (childTail != null) { + result.append("\n" + LocalizedStrings.SystemMemberImpl_TAIL_OF_CHILD_LOG.toLocalizedString() + "\n"); + result.append(childTail); + } + return result.toString(); + } + } + + public final java.util.Properties getLicense() { + GemFireVM vm = getGemFireVM(); + if (vm == null) return null; + return new Properties(); + } + + public final String getVersion() { + GemFireVM vm = getGemFireVM(); + if (vm == null) return null; + return vm.getVersionInfo(); + } + + public StatisticResource[] getStat(String statisticsTypeName) + throws AdminException { + StatisticResource[] res = new StatisticResource[0]; + if (this.vm != null) { + res = getStatsImpl(this.vm.getStats(statisticsTypeName)); + } + return res.length==0 ? null : res; + } + + public StatisticResource[] getStats() + throws AdminException { + StatisticResource[] statsImpl = new StatisticResource[0]; + if (this.vm != null) { + statsImpl = getStatsImpl(this.vm.getStats(null)); + } + return statsImpl; + } + + public final boolean hasCache() { + GemFireVM member = getGemFireVM(); + if (member == null) { + return false; + + } else { + return member.getCacheInfo() != null; + } + } + + public final SystemMemberCache getCache() + throws AdminException + { + GemFireVM vm = getGemFireVM(); // fix for bug 33505 + if (vm == null) return null; + try { + return createSystemMemberCache(vm); + + } catch (CancelException ex) { + return null; + + } catch (CacheDoesNotExistException ex) { + return null; + } + } + + public void refreshConfig() + throws AdminException { + GemFireVM vm = getGemFireVM(); + if (vm == null) return; + refreshConfig(vm.getConfig()); + } + + /** + * Sets the value of this system member's distribution-related + * configuration based on the given <code>Config</code> object. + */ + public final void refreshConfig(Config config) + throws AdminException { + if (config == null) { + throw new AdminException(LocalizedStrings.SystemMemberImpl_FAILED_TO_REFRESH_CONFIGURATION_PARAMETERS_FOR_0.toLocalizedString(new Object[] {getId()})); + } + + String[] names = config.getAttributeNames(); + if (names == null || names.length < 1) { + throw new AdminException(LocalizedStrings.SystemMemberImpl_FAILED_TO_REFRESH_CONFIGURATION_PARAMETERS_FOR_0.toLocalizedString(new Object[] {getId()})); + } + + for (int i = 0; i < names.length; i++) { + String name = names[i]; + Object value = config.getAttributeObject(name); + if (value != null) { + ConfigurationParameter parm = createConfigurationParameter( + name, // name + config.getAttributeDescription(name), // description + value, // value + config.getAttributeType(name), // valueType + config.isAttributeModifiable(name) ); // isModifiable + ((ConfigurationParameterImpl) parm).addConfigurationParameterListener(this); + this.parms.put(name, parm); + } + } + } + + public final ConfigurationParameter[] getConfiguration() { + ConfigurationParameter[] array = + new ConfigurationParameter[this.parms.size()]; + this.parms.values().toArray(array); + return array; + } + + public ConfigurationParameter[] + setConfiguration(ConfigurationParameter[] parms) + throws AdminException { + + for (int i = 0; i < parms.length; i++) { + ConfigurationParameter parm = parms[i]; + this.parms.put(parm.getName(), parm); + } + + GemFireVM vm = getGemFireVM(); + if (vm != null) { + // update internal vm's config... + Config config = vm.getConfig(); + for (int i = 0; i < parms.length; i++) { + config.setAttributeObject(parms[i].getName(), parms[i].getValue(), ConfigSource.runtime()); + } + vm.setConfig(config); + } + + return this.getConfiguration(); + } + + public SystemMemberType getType() { + return SystemMemberType.APPLICATION; + } + + // ------------------------------------------------------------------------- + // Listener callbacks + // ------------------------------------------------------------------------- + + // -- ConfigurationParameterListener --- + public void configurationParameterValueChanged(ConfigurationParameter parm) { + try { + setConfiguration(new ConfigurationParameter[] { parm }); + } catch (AdminException e) { + // this shouldn't occur since this is a config listener method... + logger.warn(e.getMessage(), e); + throw new RuntimeAdminException(e); + } catch (java.lang.Exception e) { + logger.warn(e.getMessage(), e); + } +// catch (java.lang.RuntimeException e) { +// logWriter.warning(e); +// throw e; +// } + catch (VirtualMachineError err) { + SystemFailure.initiateFailure(err); + // If this ever returns, rethrow the error. We're poisoned + // now, so don't let this thread continue. + throw err; + } catch (java.lang.Error e) { + // Whenever you catch Error or Throwable, you must also + // catch VirtualMachineError (see above). However, there is + // _still_ a possibility that you are dealing with a cascading + // error condition, so you also need to check to see if the JVM + // is still usable: + SystemFailure.checkFailure(); + logger.error(e.getMessage(), e); + throw e; + } + } + + // ------------------------------------------------------------------------- + // Overridden method(s) from java.lang.Object + // ------------------------------------------------------------------------- + + @Override + public String toString() { + return getName(); + } + + // ------------------------------------------------------------------------- + // Template methods with default behavior impl'ed. Override if needed. + // ------------------------------------------------------------------------- + + /** + * Returns the <code>GemFireVM</code> that underlies this + * <code>SystemMember</code>. + */ + protected final GemFireVM getGemFireVM() { + return this.vm; + } + + /** + * Sets the <code>GemFireVM</code> that underlies this + * <code>SystemMember</code>. This method is used when a member, + * such as a cache server, is started by the admin API. + */ + void setGemFireVM(GemFireVM vm) throws AdminException { + this.vm = vm; + if (vm != null) { + this.internalId = vm.getId(); + this.id = this.internalId.toString(); + this.name = vm.getName(); + this.host = InetAddressUtil.toString(vm.getHost()); + } else { + this.internalId = null; + this.id = null; + // leave this.name set to what it is (how come?) + this.host = this.getHost(); + } + + if (DistributionConfig.DEFAULT_NAME.equals(this.name)) { + // Fix bug 32877 + this.name = this.id; + } + + if (vm != null) { + this.refreshConfig(); + } + } + + /** + * Updates this SystemMember instance using the corresponding + * InternalDistributedMember + * + * @param member + * InternalDistributedMember instance to update this SystemMember + * + * @since GemFire 6.5 + */ + private void updateByInternalDistributedMember( + InternalDistributedMember member) { + if (member != null) { + this.internalId = member; + this.id = this.internalId.toString(); + this.host = this.internalId.getHost(); + this.name = this.internalId.getName(); + if (this.name == null || + DistributionConfig.DEFAULT_NAME.equals(this.name)) { + /* + * name could be null & referring to description of a fix for 32877 + */ + this.name = this.id; + } + } + } + + /** + * Template method for creating {@link StatisticResource}. + * + * @param stat the internal stat resource to wrap with {@link StatisticResource} + * @return new impl instance of {@link StatisticResource} + */ + protected StatisticResource createStatisticResource(StatResource stat) + throws AdminException { + return new StatisticResourceImpl(stat, this); + } + + /** + * Template method for creating {@link ConfigurationParameter}. + * + * @param name the name of this parameter which cannot change + * @param description full description to use + * @param value the value of this parameter + * @param type the class type of the value + * @param userModifiable true if this is modifiable; false if read-only + * @return new impl instance of {@link ConfigurationParameter} + */ + protected ConfigurationParameter createConfigurationParameter(String name, + String description, + Object value, + Class type, + boolean userModifiable) { + return new ConfigurationParameterImpl( + name, description, value, type, userModifiable); + } + + /** + * Template method for creating {@link SystemMemberCache}. + * + * @param vm the GemFire vm to retrieve cache info from + * @return new impl instance of {@link SystemMemberCache} + */ + protected SystemMemberCache createSystemMemberCache(GemFireVM vm) + throws AdminException + { + return new SystemMemberCacheImpl(vm); + } + + /** Wrap the internal stats with impls of {@link StatisticResource} */ + protected StatisticResource[] getStatsImpl(StatResource[] stats) + throws AdminException { + List statList = new ArrayList(); + for (int i = 0; i < stats.length; i++) { + statList.add(createStatisticResource(stats[i])); + } + return (StatisticResource[]) statList.toArray(new StatisticResource[0]); + } + + public String[] getRoles() { + Set roles = this.internalId.getRoles(); + String[] roleNames = new String[roles.size()]; + Iterator iter = roles.iterator(); + for (int i = 0; i < roleNames.length; i++) { + Role role = (Role) iter.next(); + roleNames[i] = role.getName(); + } + return roleNames; + } + + public DistributedMember getDistributedMember() { + return this.internalId; + } +} + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionEventImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionEventImpl.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionEventImpl.java new file mode 100644 index 0000000..8a56d86 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionEventImpl.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.impl; + +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.cache.Operation; +import org.apache.geode.internal.admin.api.SystemMemberCacheListener; +import org.apache.geode.internal.admin.api.SystemMemberRegionEvent; + +/** + * An event that describes an operation on a region. + * Instances of this are delivered to a {@link SystemMemberCacheListener} when a + * a region comes or goes. + * + * @since GemFire 5.0 + */ +public class SystemMemberRegionEventImpl + extends SystemMemberCacheEventImpl + implements SystemMemberRegionEvent +{ + + /** + * The path of region created/destroyed + */ + private final String regionPath; + + /////////////////////// Constructors /////////////////////// + + /** + * Creates a new <code>SystemMemberRegionEvent</code> for the member + * with the given id. + */ + protected SystemMemberRegionEventImpl(DistributedMember id, Operation op, String regionPath) { + super(id, op); + this.regionPath = regionPath; + } + + ///////////////////// Instance Methods ///////////////////// + + public String getRegionPath() { + return this.regionPath; + } + + @Override + public String toString() { + return super.toString() + " region=" + this.regionPath; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionImpl.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionImpl.java new file mode 100644 index 0000000..857f709 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionImpl.java @@ -0,0 +1,381 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.impl; + +import org.apache.geode.cache.*; +//import org.apache.geode.internal.Assert; +//import org.apache.geode.internal.admin.*; +import org.apache.geode.internal.admin.api.AdminException; +import org.apache.geode.internal.admin.api.SystemMemberRegion; +import org.apache.geode.internal.admin.remote.*; + +import java.io.File; +import java.util.*; + +/** + * View of a region in a GemFire system member's cache. + * + * @since GemFire 3.5 + */ +public class SystemMemberRegionImpl implements SystemMemberRegion { + + private AdminRegion r; + private RegionAttributes ra; + private CacheStatistics rs; + private Set subregionNames; + private Set subregionFullPaths; + private int entryCount; + private int subregionCount; + + /** The cache to which this region belongs */ + private final SystemMemberCacheImpl cache; + + // constructors + public SystemMemberRegionImpl(SystemMemberCacheImpl cache, Region r) + { + this.cache = cache; + this.r = (AdminRegion)r; + } + + private void refreshFields() { + this.ra = this.r.getAttributes(); + if (getStatisticsEnabled() && !this.ra.getDataPolicy().withPartitioning()) { + this.rs = this.r.getStatistics(); + } else { + this.rs = null; + } + { // set subregionNames + Set s = this.r.subregions(false); + Set names = new TreeSet(); + Set paths = new TreeSet(); + Iterator it = s.iterator(); + while (it.hasNext()) { + Region r = (Region)it.next(); + String name = r.getName(); + names.add(name); + paths.add(this.getFullPath() + Region.SEPARATOR_CHAR + name); + } + this.subregionNames = names; + this.subregionFullPaths = paths; + } + try { + int[] sizes = this.r.sizes(); + this.entryCount = sizes[0]; + this.subregionCount = sizes[1]; + } catch (CacheException ignore) { + this.entryCount = 0; + this.subregionCount = 0; + } + } + + // attributes + public String getName() { + return this.r.getName(); + } + + public String getFullPath() { + return this.r.getFullPath(); + } + + public java.util.Set getSubregionNames() { + return this.subregionNames; + } + + public java.util.Set getSubregionFullPaths() { + return this.subregionFullPaths; + } + + public String getUserAttribute() { + return (String)r.getUserAttribute(); + } + + public String getCacheLoader() { + Object o = this.ra.getCacheLoader(); + if (o == null) { + return ""; + } else { + return o.toString(); + } + } + public String getCacheWriter() { + Object o = this.ra.getCacheWriter(); + if (o == null) { + return ""; + } else { + return o.toString(); + } + } + + public String getKeyConstraint() { + Class constraint = this.ra.getKeyConstraint(); + if (constraint == null) { + return ""; + } else { + return constraint.getName(); + } + } + + public String getValueConstraint() { + Class constraint = this.ra.getValueConstraint(); + if (constraint == null) { + return ""; + } else { + return constraint.getName(); + } + } + + public boolean getEarlyAck() { + return this.ra.getEarlyAck(); + } + + public int getRegionTimeToLiveTimeLimit() { + return this.ra.getRegionTimeToLive().getTimeout(); + } + + public ExpirationAction getRegionTimeToLiveAction() { + return this.ra.getRegionTimeToLive().getAction(); + } + + public int getEntryTimeToLiveTimeLimit() { + return this.ra.getEntryTimeToLive().getTimeout(); + } + + public ExpirationAction getEntryTimeToLiveAction() { + return this.ra.getEntryTimeToLive().getAction(); + } + + public String getCustomEntryTimeToLive() { + Object o = this.ra.getCustomEntryTimeToLive(); + if (o == null) { + return ""; + } else { + return o.toString(); + } + } + + public int getRegionIdleTimeoutTimeLimit() { + return this.ra.getRegionIdleTimeout().getTimeout(); + } + + public ExpirationAction getRegionIdleTimeoutAction() { + return this.ra.getRegionIdleTimeout().getAction(); + } + + public int getEntryIdleTimeoutTimeLimit() { + return this.ra.getEntryIdleTimeout().getTimeout(); + } + + public ExpirationAction getEntryIdleTimeoutAction() { + return this.ra.getEntryIdleTimeout().getAction(); + } + + public String getCustomEntryIdleTimeout() { + Object o = this.ra.getCustomEntryIdleTimeout(); + if (o == null) { + return ""; + } else { + return o.toString(); + } + } + + public MirrorType getMirrorType() { + return this.ra.getMirrorType(); + } + + public DataPolicy getDataPolicy() { + return this.ra.getDataPolicy(); + } + + public Scope getScope() { + return this.ra.getScope(); + } + + public EvictionAttributes getEvictionAttributes() { + return this.ra.getEvictionAttributes(); + } + + /** + * This method will return an empty string if there are no CacheListeners + * defined on the region. If there are more than 1 CacheListeners defined, + * this method will return the description of the 1st CacheListener in the + * list returned by the getCacheListeners method. If there is only one + * CacheListener defined this method will return it's description + * + * @return String the region's <code>CacheListener</code> description + * @deprecated as of 6.0, use {@link #getCacheListeners} instead + */ + @Deprecated + public String getCacheListener() { + String[] o = this.getCacheListeners(); + if (o.length == 0) { + return ""; + } + else { + return o[0].toString(); + } + } + + /** + * This method will return an empty array if there are no CacheListeners + * defined on the region. If there are one or more than 1 CacheListeners + * defined, this method will return an array which has the description of all + * the CacheListeners + * + * @return String[] the region's <code>CacheListeners</code> descriptions as a + * String array + * @since GemFire 6.0 + */ + public String[] getCacheListeners() { + Object[] o = this.ra.getCacheListeners(); + String[] ret = null; + if (o == null || o.length == 0) { + ret = new String[0]; + } + else { + ret = new String[o.length]; + for (int i = 0; i < o.length; i++) { + ret[i] = o[i].toString(); + } + } + return ret; + } + + public int getInitialCapacity() { + return this.ra.getInitialCapacity(); + } + + public float getLoadFactor() { + return this.ra.getLoadFactor(); + } + + public int getConcurrencyLevel() { + return this.ra.getConcurrencyLevel(); + } + + public boolean getConcurrencyChecksEnabled() { + return this.ra.getConcurrencyChecksEnabled(); + } + + public boolean getStatisticsEnabled() { + return this.ra.getStatisticsEnabled(); + } + + public boolean getPersistBackup() { + return this.ra.getPersistBackup(); + } + + public DiskWriteAttributes getDiskWriteAttributes() { + return this.ra.getDiskWriteAttributes(); + } + + public File[] getDiskDirs() { + return this.ra.getDiskDirs(); + } + + public int getEntryCount() { + return this.entryCount; + } + + public int getSubregionCount() { + return this.subregionCount; + } + + public long getLastModifiedTime() { + if (this.rs == null) { + return 0; + } else { + return this.rs.getLastModifiedTime(); + } + } + + public long getLastAccessedTime() { + if (this.rs == null) { + return 0; + } else { + return this.rs.getLastAccessedTime(); + } + } + + public long getHitCount() { + if (this.rs == null) { + return 0; + } else { + return this.rs.getHitCount(); + } + } + + public long getMissCount() { + if (this.rs == null) { + return 0; + } else { + return this.rs.getMissCount(); + } + } + + public float getHitRatio() { + if (this.rs == null) { + return 0; + } else { + return this.rs.getHitRatio(); + } + } + + // operations + public void refresh() { + refreshFields(); + } + + /** + * Returns a string representation of the object. + * + * @return a string representation of the object + */ + @Override + public String toString() { + return getName(); + } + + public SystemMemberRegion createSubregion(String name, + RegionAttributes attrs) + throws AdminException { + + Region r = + this.cache.getVM().createSubregion(this.cache.getCacheInfo(), + this.getFullPath(), name, attrs); + if (r == null) { + return null; + + } else { + return this.cache.createSystemMemberRegion(r); + } + + } + + public MembershipAttributes getMembershipAttributes() { + return this.ra.getMembershipAttributes(); + } + + public SubscriptionAttributes getSubscriptionAttributes() { + return this.ra.getSubscriptionAttributes(); + } + + public PartitionAttributes getPartitionAttributes() { + return this.ra.getPartitionAttributes(); + } + +} + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMembershipEventImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMembershipEventImpl.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMembershipEventImpl.java new file mode 100644 index 0000000..1386834 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMembershipEventImpl.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.impl; + +import org.apache.geode.distributed.DistributedMember; +import org.apache.geode.internal.admin.api.SystemMembershipEvent; +import org.apache.geode.internal.admin.api.SystemMembershipListener; + +/** + * An event delivered to a {@link SystemMembershipListener} when a + * member has joined or left the distributed system. + * + * @since GemFire 5.0 + */ +public class SystemMembershipEventImpl implements SystemMembershipEvent { + + /** The id of the member that generated this event */ + private DistributedMember id; + + /////////////////////// Constructors /////////////////////// + + /** + * Creates a new <code>SystemMembershipEvent</code> for the member + * with the given id. + */ + protected SystemMembershipEventImpl(DistributedMember id) { + this.id = id; + } + + ///////////////////// Instance Methods ///////////////////// + + public String getMemberId() { + return this.id.toString(); + } + + public DistributedMember getDistributedMember() { + return this.id; + } + +// /** +// * Returns the user specified callback object associated with this +// * membership event. Note that the callback argument is always +// * <code>null</code> for the event delivered to the {@link +// * SystemMembershipListener#memberCrashed} method. +// * +// * @since GemFire 4.0 +// */ +// public Object getCallbackArgument() { +// throw new UnsupportedOperationException("Not implemented yet"); +// } + + @Override + public String toString() { + return "Member " + this.getMemberId(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/package.html ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/package.html b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/package.html new file mode 100644 index 0000000..cfa4e41 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/package.html @@ -0,0 +1,53 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You 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. +--> +<HTML> +<BODY> + +<P>Contains the implementation of the external admin APIs from +<a href="{@docRoot}/org/apache/geode/internal/admin/api/package-summary.html#package_description">org.apache.geode.internal.admin.api</a>.</P> + +<H2>Monitoring the "health" of GemFire</H2> + +<P>The health monitoring implementation comes in two pieces. On the +client (administrator) side there is a {@link +GemFireHealthImpl} object that is +responsible for configuring a {@link +org.apache.geode.distributed.internal.HealthMonitorImpl} that runs +in the member VMs. The communication between the administration +process and the member process is accomplised via a {@link +org.apache.geode.internal.admin.GemFireVM GemFireVM} from the +"internal admin" API. The <code>HealthMonitorImpl</code> is a thread +that periodically consults a {@link +GemFireHealthEvaluator} that uses +a {@link GemFireHealthConfigImpl} +to determine the health of a GemFire component. Most of the health +criteria are based on {@linkplain org.apache.geode.Statistics +statistics} that are maintained by GemFire. When the +<code>HealthMonitorImpl</code> determines that the health of a GemFire +component has changed, it alerts the administrator process via a +{@link org.apache.geode.internal.admin.HealthListener}.</P> + + +<P>The below diagram explains how the classes that monitor the health +of GemFire are implemented.</P> + +<CENTER> +<IMG src="{@docRoot}/javadoc-images/health-classes.gif" HEIGHT="803" /> +</CENTER> + +</BODY> +</HTML> http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0221bed/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/Agent.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/Agent.java b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/Agent.java new file mode 100644 index 0000000..17dd4b7 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/Agent.java @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.geode.internal.admin.api.jmx; + +import org.apache.geode.LogWriter; +import org.apache.geode.internal.admin.api.AdminException; +import org.apache.geode.internal.admin.api.AdminDistributedSystem; + +//import javax.management.MBeanException; +import javax.management.MalformedObjectNameException; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +/** + * A server component that provides administration-related information + * about a GemFire distributed system via the Java Management + * Extension JMX API. When a JMX <code>Agent</code> is created, it + * registers an MBean that represents {@link #getObjectName itself}. + * Click <A href="doc-files/mbeans-descriptions.html">here</A> for a + * description of the attributes, operations, and notifications of + * this and other GemFire JMX MBeans. + * + * <P> + * + * The GemFire JMX Agent currently supports three JMX "adapters" + * through which clients can access the GemFire management beans: an + * "HTTP adapter" that allows a web browser client to view and modify + * management beans via HTTP or HTTPS, an "RMI adapter" that allows + * Java programs to access management beans using Remote Method + * Invocation, and an "SNMP adapter" that allows SNMP to access + * management beans. Information about configuring these adapters can + * be found in {@link AgentConfig}. + * + * <P> + * + * In most distributed caching architectures, JMX administration + * agents are run in their own processes. A stand-alone JMX agent is + * managed using the <code>agent</code> command line utility: + * + * <PRE> + * $ agent start + * </PRE> + * + * This class allows a GemFire application VM to host a JMX management + * agent. Architectures with "co-located" JMX agents reduce the + * number of overall proceses required. However, hosting a JMX + * management agent in the same VM as a GemFire application is not + * generally recommended because it adds extra burden to an + * application VM and in the event that the application VM exits the + * administration information will no longer be available. + * + * @see AgentConfig + * @see AgentFactory + * + * @since GemFire 4.0 + * @deprecated as of 7.0 use the <code><a href="{@docRoot}/org/apache/geode/management/package-summary.html">management</a></code> package instead + */ +public interface Agent { + + /** Lookup name for RMIConnector when rmi-registry-enabled is true */ + public static final String JNDI_NAME = "/jmxconnector"; + + ////////////////////// Instance Methods ////////////////////// + + /** + * Returns the configuration object for this JMX Agent. + */ + public AgentConfig getConfig(); + + /** + * Starts this JMX Agent and its associated adapters. This method + * does not {@linkplain #connectToSystem connect} to the distributed + * system. + */ + public void start(); + + /** + * Returns the JMX <code>MBeanServer</code> with which GemFire + * MBeans are registered or <code>null</code> if this + * <code>Agent</code> is not started. + */ + public MBeanServer getMBeanServer(); + + /** + * {@linkplain #disconnectFromSystem Disconnects} from the + * distributed system and stops this JMX Agent and all of its + * associated adapters. + */ + public void stop(); + + /** + * Returns the <code>ObjectName</code> of the JMX management bean + * that represents this agent or <code>null</code> if this + * <code>Agent</code> has not been started. + */ + public ObjectName getObjectName(); + + /** + * Returns whether or not this JMX <code>Agent</code> is currently + * providing information about a distributed system. + */ + public boolean isConnected(); + + /** + * Connects to the distributed system described by this <code>Agent</code>'s + * configuration. + * + * @return The object name of the system that the <code>Agent</code> + * is now connected to. + */ + public ObjectName connectToSystem() + throws AdminException, MalformedObjectNameException; + + /** + * Returns the <code>AdminDistributedSystem</code> that underlies + * this JMX <code>Agent</code> or <code>null</code> is this agent is + * not {@linkplain #isConnected connected}. + */ + public AdminDistributedSystem getDistributedSystem(); + + /** + * Returns the object name of the JMX MBean that represents the + * distributed system administered by this <code>Agent</code> or + * <code>null</code> if this <code>Agent</code> has not {@linkplain + * #connectToSystem connected} to the distributed system. + */ + public ObjectName manageDistributedSystem() + throws MalformedObjectNameException; + + /** + * Disconnects this agent from the distributed system and + * unregisters the management beans that provided information about + * it. However, this agent's adapters are not stopped and it is + * possible to reconfigure this <code>Agent</code> to connect to + * another distributed system. + */ + public void disconnectFromSystem(); + + /** + * Saves the configuration for this <code>Agent</code> to the file + * specified by @link AgentConfig#getPropertyFile. + */ + public void saveProperties(); + + /** + * Returns the <code>LogWriter</code> used for logging information. + */ + public LogWriter getLogWriter(); + +}