IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Grid computing  >

Crunch big numbers with GT3 using a quadratic sieve

Listing 3: Service implementation

developerWorks

Return to article.

package factorization.service.impl;
/**
 * Title: Factorization Library
 * Description: A factorization lib based on the quadratic sieve
 * Copyright: Copyright (c) 2004
 * Company: ACME
 * @author Vladimir Silva
 * @version 1.0
 */
import org.globus.ogsa.impl.ogsi.GridServiceImpl;
import factorization.service.Factorization.FactorizationPortType;
import java.rmi.RemoteException;

import javax.math.factorization.Factorizer;

/**
 * Factorization service Implementation
 */
public class FactorizationImpl extends GridServiceImpl 
   implements FactorizationPortType
{
      public FactorizationImpl() {
            super("Factorization Service");
      }

      /**
       * Factorization Method
       * @param bigNum Number to factor
       * @param outFile Full path to the server side Output file
       * (Contains factors pd(1)^ exp(1) * .....
       * @param options Use "-verbose" to display fac output in the GT server log
       */
      public String factorize(String bigNum, String outFile, String options)
	throws RemoteException
      {
            String[] args = {"-n", bigNum, "-out", outFile, options};

            try {
                  Factorizer f = new Factorizer(args);
                  // dump output: to the console or a file
                  f.dumpOutput();
                  return buildXML(false, "Out in: " + outFile);
            }
            catch (Exception ex) {
                  return buildXML(true, ex.getClass().getName() + ": " +  
                  ex.getMessage());
            }

      }

      /*
       * An XML string is returned w/ service status
       */
      private String buildXML(boolean error, String text) {
            return "<xml><error>" + error + "</error><text>" + text +
             "</text></xml>";
      }
}

Return to article.

    关于 IBM 隐私条约 联系 IBM 使用条款