/*
* LICENSE AGREEMENT
*
* GRIDGAIN 1.0 - GRID COMPUTING FOR JAVA.
* COPYRIGHT (C) 2005-2007 GRIDGAIN SYSTEMS. ALL RIGHTS RESERVED.
*
* THIS IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR
* MODIFY IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC
* LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; EITHER
* VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER
* VERSION.
*
* THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE
* GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
*
* YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC
* LICENSE ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE
* SOFTWARE FOUNDATION, INC., 51 FRANKLIN ST, FIFTH FLOOR, BOSTON, MA
* 02110-1301 USA
*/
package org.gridgain.examples.helloworld.gridify.context;
import java.lang.management.*;
import java.lang.reflect.*;
import org.gridgain.grid.*;
import org.gridgain.grid.gridify.*;
/**
* This context factory will grid-enable methods only if local node's heap
* memory usage is below 80% of all heap memory available. It also sets
* timeout of method execution on the grid to 2 seconds.
*
* @author 2005-2007 Copyright (C) GridGain Systems. All Rights Reserved.
* @version 1.0.0-07022007
*/
public class GridifyHelloWorldContextFactory implements GridifyContextFactory {
/**
* Creates custom {@link GridifyContext} context.
*
* @see GridifyContextFactory#create(Gridify, Object, Method, Object[])
*/
public GridifyContext create(Gridify gridify, Object obj, Method method, Object[] params) throws GridException {
MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
if (heap.getUsed() >= 0.8 * heap.getMax()) {
return null;
}
GridifyContextAdapter ctx = new GridifyContextAdapter(gridify);
ctx.setTimeout(2000);
return ctx;
}
}