📄 gridcounterportlet.java
字号:
package org.gridlab.gridsphere.portlets;import org.globus.ogsa.samples.counter.CounterPortType;import org.globus.ogsa.samples.counter.service.CounterServiceGridLocator;import org.globus.ogsa.utils.GridServiceFactory;import org.gridforum.ogsi.Factory;import org.gridforum.ogsi.LocatorType;import org.gridforum.ogsi.OGSIServiceGridLocator;import org.gridlab.gridsphere.portlet.PortletConfig;import org.gridlab.gridsphere.portlet.PortletRequest;import org.gridlab.gridsphere.portlet.AbstractPortlet;import org.gridlab.gridsphere.portlet.PortletException;import org.gridlab.gridsphere.portlet.PortletResponse;import org.gridlab.gridsphere.portlet.PortletURI;import org.gridlab.gridsphere.event.ActionEvent;import javax.servlet.UnavailableException;import java.net.URL;import java.io.IOException;import java.io.PrintWriter;import java.rmi.RemoteException;/** * @author <a href="mailto:novotny@aei.mpg.de">Jason Novotny</a> * @version $Id: GridCounterPortlet.java,v 1.1 2004/01/03 11:46:32 jdnovotny Exp $ */public class GridCounterPortlet extends AbstractPortlet { public static final String VIEW_JSP = "/jsp/ogsa/counter/view_counter.jsp"; // Create a URL for the counter service private static final String counterUrl = "http://127.0.0.1:8080/ogsa/services/samples/counter/basic/CounterFactoryService"; private LocatorType locator = null; private CounterPortType counter = null; public void init(PortletConfig config) throws UnavailableException { super.init(config); try { // Create a grid service handle from the service URL URL GSH = new URL(counterUrl); // Get a reference to the CounterService Factory OGSIServiceGridLocator gridLocator = new OGSIServiceGridLocator(); Factory factory = gridLocator.getFactoryPort(GSH); GridServiceFactory counterFactory = new GridServiceFactory(factory); // Create a new CounterService instance and get a reference to its Counter PortType. locator = counterFactory.createService(); CounterServiceGridLocator counterLocator = new CounterServiceGridLocator(); counter = counterLocator.getCounterPort(locator); } catch (Exception e) { getPortletLog().error("Unable to create OGSA counter service instance", e); } } public void actionPerformed(ActionEvent evt) throws PortletException { PortletRequest req = evt.getPortletRequest(); /** * Return the portlet response associated with this action event * * @return the <code>PortletResponse</code> */ System.err.println("in actionperformed of GridCOunterPortlet"); int count = 0; String countStr = req.getParameter("count"); /** * Returns a map of the parameters of this request. * * @return a map of parameters */ try { count = Integer.parseInt(countStr); } catch (IllegalArgumentException e) { // do nothing } String operation = req.getParameter("operation"); if (operation != null) { if (operation.equals("Add")) { try { System.err.println("adding " + count + " to counter"); counter.add(count); } catch (RemoteException e) { getPortletLog().error("Failed invoking add on counter", e); } } if (operation.equals("Subtract")) { try { counter.subtract(count); } catch (RemoteException e) { getPortletLog().error("Failed invoking subtract on counter", e); } } } } public void doView(PortletRequest req, PortletResponse res) throws IOException, PortletException { PortletURI uri = res.createURI(); uri.addAction("submit"); req.setAttribute("uri", uri.toString()); String counterVal = "0"; try { counterVal = String.valueOf(counter.getValue()); } catch (RemoteException e) { getPortletLog().error("Unable to get counter value", e); } req.setAttribute("counterVal", counterVal); getConfig().getContext().include(VIEW_JSP, req, res); } public void doHelp(PortletRequest req, PortletResponse res) throws IOException, PortletException { PrintWriter out = res.getWriter(); out.println("This portlet demonstrates the GT3 counter service."); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -