# HG changeset patch # User Dominic Cleal # Date 1228956568 0 # Node ID e59e6471ce44a0f827809c6086795adeda6ce29b Initial version of a Blitz colocated agent to provide JMX MXBeans access to its statistics diff -r 000000000000 -r e59e6471ce44 .classpath --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,9 @@ + + + + + + + + + diff -r 000000000000 -r e59e6471ce44 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,3 @@ +build_ide/ +dist/ + diff -r 000000000000 -r e59e6471ce44 .project --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,17 @@ + + + blitz_jmxagent + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff -r 000000000000 -r e59e6471ce44 .settings/org.eclipse.jdt.ui.prefs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.jdt.ui.prefs Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,3 @@ +#Wed Dec 10 12:55:47 GMT 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.ui.text.custom_code_templates= diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/AbstractStatsImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/AbstractStatsImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.Collection; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.Stat; + +public abstract class AbstractStatsImpl +{ + private StatsAdmin admin_; + private Class statClazz_; + + public AbstractStatsImpl(StatsAdmin admin, Class stat) + { + admin_ = admin; + statClazz_ = stat; + } + + @SuppressWarnings("unchecked") + protected Collection getStatistics() throws RemoteException + { + Collection ret = new ArrayList(); + for (Stat stat : admin_.getStats()) + { + if (statClazz_.isInstance(stat)) + { + ret.add((T) statClazz_.cast(stat)); + } + } + + return ret; + } + + @Override + public String toString() + { + String name = getClass().getSimpleName(); + if (name.endsWith("Impl")) + { + name = name.substring(0, name.length() - 4); + } + + return "type=" + name; + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/BlockingOpsImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/BlockingOpsImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.Iterator; + +import net.scatterspace.blitz.jmx.iface.BlockingOpsMXBean; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.BlockingOpsStat; + +/** + * MXBean to interface to {@link BlockingOpsStat}. + */ +public class BlockingOpsImpl extends AbstractStatsImpl + implements BlockingOpsMXBean +{ + public BlockingOpsImpl(StatsAdmin admin) + { + super(admin, BlockingOpsStat.class); + } + + public int getReaders() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getReaders(); + } + + public int getTakers() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getTakers(); + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/EventQueueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/EventQueueImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.Iterator; + +import net.scatterspace.blitz.jmx.iface.EventQueueMXBean; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.EventQueueStat; + +/** + * MXBean to interface to {@link EventQueueStat}. + */ +public class EventQueueImpl extends AbstractStatsImpl + implements EventQueueMXBean +{ + public EventQueueImpl(StatsAdmin admin) + { + super(admin, EventQueueStat.class); + } + + public int getPersistentCount() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getPersistentCount(); + } + + public int getTransientCount() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getTransientCount(); + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/IOImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/IOImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.Iterator; + +import net.scatterspace.blitz.jmx.iface.IOMXBean; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.IOStat; + +/** + * MXBean to interface to {@link IOStat}. + */ +public class IOImpl extends AbstractStatsImpl implements IOMXBean +{ + public IOImpl(StatsAdmin admin) + { + super(admin, IOStat.class); + } + + public int getQueueSize() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getQueueSize(); + } + + public double getInOutRatio() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getInOutRatio(); + } + + public double getTimePerIn() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getTimePerIn(); + } + + public double getTimePerOut() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getTimePerOut(); + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/InstanceCountImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/InstanceCountImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.Iterator; + +import net.scatterspace.blitz.jmx.iface.InstanceCountMXBean; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.InstanceCount; + +/** + * MXBean to interface to {@link InstanceCount}. + */ +public class InstanceCountImpl extends AbstractStatsImpl implements InstanceCountMXBean +{ + private String type_; + + public InstanceCountImpl(StatsAdmin admin, String type) + { + super(admin, InstanceCount.class); + type_ = type; + } + + public int getCount() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getCount(); + } + + @Override + public String toString() + { + return super.toString() + ",class=" + type_; + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/JmxAgent.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/JmxAgent.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.scatterspace.blitz.jmx; + +import java.lang.management.ManagementFactory; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Timer; +import java.util.TimerTask; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import net.jini.admin.Administrable; +import net.jini.space.JavaSpace; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.remote.user.ColocatedAgent; +import org.dancres.blitz.stats.OpStat; +import org.dancres.blitz.stats.Stat; + +/** + * Agent colocated inside Blitz JavaSpaces that provides JMX beans to monitor + * the space statistics and entry statistics. + */ +public class JmxAgent implements ColocatedAgent +{ + private Logger log_ = Logger.getLogger(getClass().getName()); + + private StatsAdmin stats_; + + private static final long UPDATE_INTERVAL__ = 60000; + private Timer updateTimer_ = new Timer("JmxAgent-timer", true); + private EntryUpdateTask updateTask_ = new EntryUpdateTask(); + + private MBeanServer mbs_ = ManagementFactory.getPlatformMBeanServer(); + + public void init(JavaSpace space) throws Exception + { + if (space instanceof Administrable) + { + Object admin = ((Administrable) space).getAdmin(); + if (admin instanceof StatsAdmin) + { + stats_ = (StatsAdmin) admin; + log_.log(Level.INFO, "JMX agent loaded with the StatsAdmin"); + + initialiseBeans(); + updateTimer_.schedule(updateTask_, 0, UPDATE_INTERVAL__); + } + else + { + log_.log(Level.SEVERE, + "Admin object is not Blitz StatsAdmin: " + admin); + } + } + else + { + log_.log(Level.SEVERE, + "Space object is not Administrable: " + space); + } + } + + private void initialiseBeans() throws RemoteException + { + register(new BlockingOpsImpl(stats_)); + register(new EventQueueImpl(stats_)); + register(new IOImpl(stats_)); + register(new MissedOpsImpl(stats_)); + register(new TaskQueueImpl(stats_, "Events")); + register(new TxnImpl(stats_)); + } + + private void register(Object bean) + { + try + { + mbs_.registerMBean(bean, + new ObjectName("BlitzJS:" + bean.toString())); + } + catch (Exception e) + { + log_.log(Level.WARNING, "Unable to register bean " + bean, e); + } + } + + /** + * Creates new MXBeans and register them if new entries appear in the stats + * interface. + */ + private class EntryUpdateTask extends TimerTask + { + private Collection knownTypes_ = new ArrayList(); + + @Override + public void run() + { + try + { + for (Stat stat : stats_.getStats()) + { + if (stat instanceof OpStat) + { + String type = ((OpStat) stat).getType(); + if (!knownTypes_.contains(type)) + { + registerType(type); + knownTypes_.add(type); + } + } + } + } + catch (RemoteException e) + { + log_.log(Level.WARNING, + "Remote exception while updating MXBean types", e); + } + } + + public void registerType(String type) + { + register(new OpImpl(stats_, type)); + register(new InstanceCountImpl(stats_, type)); + } + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/MissedOpsImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/MissedOpsImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.Iterator; + +import net.scatterspace.blitz.jmx.iface.MissedOpsMXBean; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.MissedOpsStat; + +/** + * MXBean to interface to {@link MissedOpsStat}. + */ +public class MissedOpsImpl extends AbstractStatsImpl + implements MissedOpsMXBean +{ + public MissedOpsImpl(StatsAdmin admin) + { + super(admin, MissedOpsStat.class); + } + + public long getMissedReads() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getMissedReads(); + } + + public long getMissedTakes() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getMissedTakes(); + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/OpImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/OpImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,94 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.Iterator; + +import net.scatterspace.blitz.jmx.iface.OpMXBean; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.OpStat; + +/** + * MXBean to interface to {@link OpStat}. + */ +public class OpImpl extends AbstractStatsImpl implements OpMXBean +{ + private String type_; + + public OpImpl(StatsAdmin admin, String type) + { + super(admin, OpStat.class); + type_ = type; + } + + public long getReads() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + while (iter.hasNext()) + { + OpStat op = iter.next(); + if (op.getOp() == OpStat.READS) + return op.getCount(); + } + + return 0; + } + + public long getTakes() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + while (iter.hasNext()) + { + OpStat op = iter.next(); + if (op.getOp() == OpStat.TAKES) + return op.getCount(); + } + + return 0; + } + + public long getWrites() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + while (iter.hasNext()) + { + OpStat op = iter.next(); + if (op.getOp() == OpStat.WRITES) + return op.getCount(); + } + + return 0; + } + + @Override + public String toString() + { + return super.toString() + ",class=" + type_; + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/TaskQueueImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/TaskQueueImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.Iterator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.scatterspace.blitz.jmx.iface.TaskQueueMXBean; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.TaskQueueStat; + +/** + * MXBean to interface to {@link TaskQueueStat}. + */ +public class TaskQueueImpl extends AbstractStatsImpl + implements TaskQueueMXBean +{ + private static Pattern toString_ = + Pattern.compile("Queue: (.+) size: ([0-9]+)"); + private String name_; + + public TaskQueueImpl(StatsAdmin admin, String name) + { + super(admin, TaskQueueStat.class); + name_ = name; + } + + public long getSize() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + while (iter.hasNext()) + { + TaskQueueStat queue = iter.next(); + Matcher match = toString_.matcher(queue.toString()); + + if (match.matches() && match.group(1).equals(name_)) + return Long.parseLong(match.group(2)); + } + + return 0; + } + + @Override + public String toString() + { + return super.toString() + ",queue=" + name_; + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/TxnImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/TxnImpl.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2008 CDO2 Limited. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CDO2 Limited nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY CDO2 LIMITED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.scatterspace.blitz.jmx; + +import java.rmi.RemoteException; +import java.util.Iterator; + +import net.scatterspace.blitz.jmx.iface.TxnMXBean; + +import org.dancres.blitz.remote.StatsAdmin; +import org.dancres.blitz.stats.TxnStat; + +/** + * MXBean to interface to {@link TxnStat}. + */ +public class TxnImpl extends AbstractStatsImpl implements TxnMXBean +{ + public TxnImpl(StatsAdmin admin) + { + super(admin, TxnStat.class); + } + + public int getActiveTxnCount() throws RemoteException + { + Iterator iter = getStatistics().iterator(); + if (!iter.hasNext()) + return 0; + + return iter.next().getActiveTxnCount(); + } +} diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/iface/BlockingOpsMXBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/iface/BlockingOpsMXBean.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,12 @@ +package net.scatterspace.blitz.jmx.iface; + +import java.rmi.RemoteException; + +public interface BlockingOpsMXBean +{ + + public int getReaders() throws RemoteException; + + public int getTakers() throws RemoteException; + +} \ No newline at end of file diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/iface/EventQueueMXBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/iface/EventQueueMXBean.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,12 @@ +package net.scatterspace.blitz.jmx.iface; + +import java.rmi.RemoteException; + +public interface EventQueueMXBean +{ + + public int getPersistentCount() throws RemoteException; + + public int getTransientCount() throws RemoteException; + +} \ No newline at end of file diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/iface/IOMXBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/iface/IOMXBean.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,16 @@ +package net.scatterspace.blitz.jmx.iface; + +import java.rmi.RemoteException; + +public interface IOMXBean +{ + + public int getQueueSize() throws RemoteException; + + public double getInOutRatio() throws RemoteException; + + public double getTimePerIn() throws RemoteException; + + public double getTimePerOut() throws RemoteException; + +} \ No newline at end of file diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/iface/InstanceCountMXBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/iface/InstanceCountMXBean.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,10 @@ +package net.scatterspace.blitz.jmx.iface; + +import java.rmi.RemoteException; + +public interface InstanceCountMXBean +{ + + public int getCount() throws RemoteException; + +} \ No newline at end of file diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/iface/MissedOpsMXBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/iface/MissedOpsMXBean.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,12 @@ +package net.scatterspace.blitz.jmx.iface; + +import java.rmi.RemoteException; + +public interface MissedOpsMXBean +{ + + public long getMissedReads() throws RemoteException; + + public long getMissedTakes() throws RemoteException; + +} \ No newline at end of file diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/iface/OpMXBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/iface/OpMXBean.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,14 @@ +package net.scatterspace.blitz.jmx.iface; + +import java.rmi.RemoteException; + +public interface OpMXBean +{ + + public long getReads() throws RemoteException; + + public long getTakes() throws RemoteException; + + public long getWrites() throws RemoteException; + +} \ No newline at end of file diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/iface/TaskQueueMXBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/iface/TaskQueueMXBean.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,9 @@ +package net.scatterspace.blitz.jmx.iface; + +import java.rmi.RemoteException; + +public interface TaskQueueMXBean +{ + public long getSize() throws RemoteException; + +} \ No newline at end of file diff -r 000000000000 -r e59e6471ce44 src/net/scatterspace/blitz/jmx/iface/TxnMXBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/net/scatterspace/blitz/jmx/iface/TxnMXBean.java Thu Dec 11 00:49:28 2008 +0000 @@ -0,0 +1,10 @@ +package net.scatterspace.blitz.jmx.iface; + +import java.rmi.RemoteException; + +public interface TxnMXBean +{ + + public int getActiveTxnCount() throws RemoteException; + +} \ No newline at end of file