looks good to me, except for the humongous class names. Is it really
necessary to call it MemoryManagerMonitoringProbe? Won't simply
MemoryProbe be enough? IMO Manager has nothing to do with a probe and
Monitoring is already implied.
And one last thing, I'm not a big fan of static state, so I naturally
dislike "TransportFactory.getInstance().setDefaultMemoryManager(mm);".
Of course this problem is not specific to just this piece of code, but
to grizzly in general. I think that the lack of a dependency injection
and a common bootstrapping mechanism is going to bite the project
sooner or later and for that reason addressing this issue should
become a priority for 2.0.
/i
On Fri, Mar 19, 2010 at 10:45 AM, Oleksiy Stashok
<Oleksiy.Stashok_at_sun.com> wrote:
> Hi,
>
> I've implemented simple interface MemoryManagerMonitoringProbe, using which
> it's possible to get statistics on Grizzly memory consumption.
> For example:
>
> MyMemoryMonitoringProbe probe = new MyMemoryMonitoringProbe();
> DefaultMemoryManager mm = new DefaultMemoryManager(probe);
>
> TransportFactory.getInstance().setDefaultMemoryManager(mm);
>
> // Start Grizzly
> ....................
>
> // Log the memory monitoring probe statistic
> log(probe.toString());
>
> //////////// Simple monitoring probe implementation
>
> public static class MyMemoryMonitoringProbe implements
> MemoryManagerMonitoringProbe {
> private final AtomicLong allocatedNew = new AtomicLong();
> private final AtomicLong allocatedFromPool = new AtomicLong();
> private final AtomicLong releasedToPool = new AtomicLong();
>
> public void allocateNewBufferEvent(int i) {
> allocatedNew.addAndGet(i);
> }
>
> public void allocateBufferFromPoolEvent(int i) {
> allocatedFromPool.addAndGet(i);
> }
>
> public void releaseBufferToPoolEvent(int i) {
> releasedToPool.addAndGet(i);
> }
>
> @Override
> public String toString() {
> StringBuilder sb = new StringBuilder();
> sb.append("allocated-memory=").append(allocatedNew.get());
> sb.append("
> allocated-from-pool=").append(allocatedFromPool.get());
> sb.append(" released-to-pool=").append(releasedToPool.get());
>
> return sb.toString();
> }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>
>