有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么我的CORBA服务器没有绑定?

目前我正在努力学习SAMS的第4章——在14天内自学CORBA

这本书中的代码似乎是有效的,除了没有像预期的那样停止之外,它还吐出了“无法绑定StockServer:”

为了解决这个问题,我修改了这本书,使用POA,并启动了tnameserv,但问题仍然存在

以下是我键入并修改的代码,而不是用idlj“编译”(生成)的代码:

// StockServerImpl.java

package StockMarket;

import java.util.Vector;

import org.omg.CORBA.*;
import org.omg.CORBA.Object;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;


/**
* StockMarket/StockServer.java .
* Generated by the IDL-to-Java compiler (portable), version "3.2"
* from StockMarket.idl
* Thursday, 30 September 2010 14:40:36 o'clock CEST
*/


// StockServerImpl implements the StockServer IDL interface
public class StockServerImpl
    extends StockServerPOA
    //extends _StockServerImplBase 
    implements StockServer 
{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    // Stock symbols and their respective values.
    private Vector<String> myStockSymbols;
    private Vector<Float> myStockValues;

    // Characters from which StockSymbol names are built.
    private static char ourCharacters[] = 
    { 
                         'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                         'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                         'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' 
    };

    // Path name for StockServer objects.
    private static String ourPathName = "StockServer";

    // Create a new StockServerImpl.
    public StockServerImpl()
    {
        myStockSymbols = new Vector<String>();
        myStockValues = new Vector<Float>();

        // Initialize the symbols and values with some random values.
        for (int i=0; i<10; i++)
        {
            // Generate a string of four random characters.
            StringBuffer stockSymbol = new StringBuffer("    ");
            for (int j=0; j<4; j++)
                { stockSymbol.setCharAt(j, ourCharacters[(int) (Math.random() * 26f)]); }

            myStockSymbols.addElement(stockSymbol.toString());

            // Give the stock a value between 0 and 100.  In this example,
            // the stock will retain this value for the duration of the
            // application.
            myStockValues.addElement(new Float(Math.random() * 100f));
        }

        // Print out the stock symbols generated above.
        System.out.println("Generated stock symbols:");
        for (int i=0; i<10; i++)
            { 
                System.out.println( 
                                    " " + myStockSymbols.elementAt(i) 
                                  + " " + myStockValues.elementAt(i)
                );
            } 
        System.out.println();
    }

    // Return the current value for the given StockSymbol.
    @Override
    public float getStockValue(String symbol) throws InvalidStockSymbolException 
    {
        // Try to find the given symbol.
        int stockIndex = myStockSymbols.indexOf(symbol);
        if (stockIndex != -1)
        {
            // Symbol found; return its value.
            return (myStockValues.elementAt(stockIndex).floatValue());
        }
        else
        {
            // Symbol was not found.
            throw new InvalidStockSymbolException();
        }
    }

    // Return a sequence of all StockSymbols known by this StockServer.
    @Override
    public String[] getStockSymbols() 
    {
        String[] symbols = new String[myStockSymbols.size()];
        myStockSymbols.copyInto(symbols);
        return symbols;
    }

    /**
     * @param ourPathName the ourPathName to set
     */
    public static void setOurPathName(String ourPathName) {
        StockServerImpl.ourPathName = ourPathName;
    }

    /**
     * @return the ourPathName
     */
    public static String getOurPathName() {
        return ourPathName;
    }

    // Create and initialize a StockServer object.
    public static void main (String args[])
    {
        NameComponent nameComponent = null;
        NamingContext namingContext = null;
        ORB orb = null;
        org.omg.CORBA.Object obj = null;
        StockServerImpl stockServer = null;

        try { orb = ORB.init(args, null); } // Initialize the ORB.
        catch (Exception ex) { System.err.println("Can't initialize ORB: " + ex.getMessage());}

        try { stockServer = new StockServerImpl(); } // Create a StockServerImpl object and register it with the ORB.
        catch (Exception ex) { System.err.println("Can't create StockServer: " + ex.getMessage()); }

        try { orb.connect(stockServer); }
        catch (Exception ex) { System.err.println("Can't connect ORB to StockServer: " + ex.getMessage()); ex.printStackTrace(); }

        try { obj = orb.resolve_initial_references("NameService"); } // Get the root naming context.
        catch (Exception ex) { System.err.println("Can't resolve NameServeice: " + ex.getMessage());  ex.printStackTrace();}

        try { namingContext = NamingContextHelper.narrow(obj); }
        catch (Exception ex) { System.err.println("Can't narrow NamingContext: " + ex.getMessage()); }

        try { nameComponent = new NameComponent (ourPathName, ""); } // Bind the StockServer object reference in the naming context
        catch (Exception ex) { System.err.println("Can't create NameComponent: " + ex.getMessage()); }

        NameComponent path[] = { nameComponent };

        try { namingContext.rebind(path, stockServer); }
        catch (Exception ex) { System.err.println("Can't rebind NameComponent to StockServer: " + ex.getMessage()); ex.printStackTrace(); }

        // Wait for invocations from clients.
        java.lang.Object waitOnMe = new java.lang.Object();
        synchronized(waitOnMe) 
        { 
            try { waitOnMe.wait(); } 
            catch (InterruptedException ex) 
            {
                System.err.println("Can't wait: " + ex.getMessage());
                ex.printStackTrace();
            } 
        }
    }

    @Override
    public Request _create_request(Context ctx, String operation,
            NVList arg_list, NamedValue result) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Request _create_request(Context ctx, String operation,
            NVList arg_list, NamedValue result, ExceptionList exclist,
            ContextList ctxlist) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object _duplicate() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public DomainManager[] _get_domain_managers() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Policy _get_policy(int policy_type) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int _hash(int maximum) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public boolean _is_equivalent(Object other) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void _release() {
        // TODO Auto-generated method stub

    }

    @Override
    public Request _request(String operation) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object _set_policy_override(Policy[] policies,
            SetOverrideType set_add) {
        // TODO Auto-generated method stub
        return null;
    }
} // interface StockServer

这是我的控制台输出,包括stacktraces:

 Generated stock symbols:
 WION 56.691833
 KQEJ 40.678604
 HCBM 82.15452
 VERC 30.731018
 LEAR 11.632088
 QLCV 58.973534
 FJDO 57.708836
 SVPS 29.638231
 NNGN 27.48113
 UAWE 65.20851

Can't connect ORB to StockServer: 
org.omg.CORBA.OBJ_ADAPTER:   vmcid: SUN  minor code: 202  completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.orbConnectError(Unknown Source)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.orbConnectError(Unknown Source)
    at com.sun.corba.se.impl.orb.ORBImpl.connect(Unknown Source)
    at StockMarket.StockServerImpl.main(StockServerImpl.java:137)
Caused by: org.omg.CORBA.BAD_OPERATION:   vmcid: SUN  minor code: 240  completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.getTypeIdsRequiresStub(Unknown Source)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.getTypeIdsRequiresStub(Unknown Source)
    at com.sun.corba.se.spi.presentation.rmi.StubAdapter.getTypeIds(Unknown Source)
    at com.sun.corba.se.impl.oa.toa.TOAImpl.connect(Unknown Source)
    ... 2 more
Can't rebind NameComponent to StockServer: 
org.omg.CORBA.BAD_PARAM:   vmcid: SUN  minor code: 206  completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.localObjectNotAllowed(Unknown Source)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.localObjectNotAllowed(Unknown Source)
    at com.sun.corba.se.impl.orbutil.ORBUtility.getIOR(Unknown Source)
    at com.sun.corba.se.impl.orbutil.ORBUtility.connectAndGetIOR(Unknown Source)
    at com.sun.corba.se.impl.encoding.CDROutputStream_1_0.write_Object(Unknown Source)
    at com.sun.corba.se.impl.encoding.CDROutputStream.write_Object(Unknown Source)
    at org.omg.CORBA.ObjectHelper.write(Unknown Source)
    at org.omg.CosNaming._NamingContextExtStub.rebind(Unknown Source)
    at StockMarket.StockServerImpl.main(StockServerImpl.java:151)

共 (0) 个答案