Package net.jini.jeri

Examples of net.jini.jeri.Endpoint


    public void run() throws Exception {
        ServerEndpoint se = getServerEndpoint();
        GetDeliveryDispatcher dispatcher = new GetDeliveryDispatcher();
        GetDeliveryContext lc = new GetDeliveryContext(dispatcher);
        Endpoint e =
            se.enumerateListenEndpoints(lc);
        dispatcher.accept();
        OutboundRequestIterator ori =
            e.newRequest(InvocationConstraints.EMPTY);
        OutboundRequest or = null;
        while (ori.hasNext()) {
            or = ori.next();
            ObjectOutputStream oos = new ObjectOutputStream(
                or.getRequestOutputStream());
            oos.writeInt(1);
            oos.close();
        }
        if (dispatcher.dispatchCalled()!=1){
            throw new TestException("Dispatcher did not receive"
                + " the value sent");
        }
        if (!or.getDeliveryStatus()) {
            throw new TestException("Call on OutboundRequest"
                + ".getDeliveryStatus() returned false for an accepted"
                + " request");
        }
        ArrayList endpoints = lc.getEndpoints();
        Iterator it = endpoints.iterator();
        while (it.hasNext()){
            ((EndpointHolder)it.next()).getListenHandle().close();
        }
        dispatcher.reject();
        try {
            ori = e.newRequest(InvocationConstraints.EMPTY);
            while (ori.hasNext()) {
                or = ori.next();
                ObjectOutputStream oos = new ObjectOutputStream(
                    or.getRequestOutputStream());
                oos.writeInt(2);
View Full Code Here


    public void run() throws Exception {
        //Start a listen opertation
        ServerSocket ss = new ServerSocket(getPort());
        acceptOneConnection(ss);
        Endpoint ep = getEndpoint();
        openClientConnection(ep);
        Socket connection = getConnection();
        if (connection==null) {
            throw new TestException("Unable to establish"
                + "client/server connection");
View Full Code Here

    public void run() throws Exception {
        //Start a listen opertation
        ServerSocket ss = new ServerSocket(getPort());
        acceptOneConnection(ss);
        Endpoint ep = getEndpoint();
        openClientConnection(ep);
        Socket connection = getConnection();
        if (connection==null) {
            throw new TestException("Unable to establish"
                + "client/server connection");
View Full Code Here

    public void registerRefs(Endpoint endpoint, Collection refs) {
  super.registerRefs(endpoint, refs);
    }

    protected DgcProxy getDgcProxy(Object endpoint) {
  Endpoint e = (Endpoint) endpoint;
  ObjectEndpoint oe = new BasicObjectEndpoint(e, Jeri.DGC_ID, false);
  InvocationHandler ih = new BasicInvocationHandler(oe, null);
  DgcServer proxy =
      (DgcServer) Proxy.newProxyInstance(getClass().getClassLoader(),
                 proxyInterfaces, ih);
View Full Code Here

      Uuid id)
        throws ExportException
    {
  List bindings = null;
  Target target = null;
  Endpoint endpoint;
  try {
      LC listenContext = new LC();
      try {
    endpoint =
        serverEndpoint.enumerateListenEndpoints(listenContext);
View Full Code Here

        // to reuse endpoint
        Thread.currentThread().sleep(1000 * 30);
        //Verify Endpoint.newRequest(null);
        endpoint = getServerEndpoint();
        context = new SETContext();
        Endpoint ep = endpoint.enumerateListenEndpoints(context);
        exceptionThrown = false;
        try {
            ep.newRequest(null);
        } catch (NullPointerException e) {
            exceptionThrown = true;
        }
        if (!exceptionThrown) {
            throw new TestException("Passing in null to"
                + " Endpoint.newRequest does not result in a"
                + " NullPointerException");
        }

        //Close listen operations
        endpoints = context.getEndpoints();
        i = endpoints.iterator();
        while (i.hasNext()) {
            ((EndpointHolder)i.next()).getListenHandle().close();
        }
        // wait to make sure resources are released before attempting
        // to reuse endpoint
        Thread.currentThread().sleep(1000 * 30);
        //Verify OutboundRequest.populateContext(null)
        endpoint = getServerEndpoint();
        context = new SETContext();
        ep = endpoint.enumerateListenEndpoints(context);
        OutboundRequestIterator it =
            ep.newRequest(InvocationConstraints.EMPTY);
        while (it.hasNext()) {
            exceptionThrown = false;
            try {
                it.next().populateContext(null);
            } catch (NullPointerException e) {
View Full Code Here

          "Access to resolve local host denied");
        }
    }
    resolvedHost = localAddr.getHostAddress();
      }
      Endpoint result = createEndpoint(
    resolvedHost,
    checkCookie(listenContext.addListenEndpoint(listenEndpoint)));
      if (logger.isLoggable(Level.FINE)) {
    logger.log(Level.FINE,
         "enumerate listen endpoints for {0}\nreturns {1}",
View Full Code Here

    public void run() throws Exception {
        ServerEndpoint se = getServerEndpoint();
        GetDeliveryDispatcher dispatcher = new GetDeliveryDispatcher();
        GetDeliveryContext lc = new GetDeliveryContext(dispatcher);
        Endpoint e =
            se.enumerateListenEndpoints(lc);
        dispatcher.reject();
        try {
            OutboundRequestIterator ori =
                e.newRequest(InvocationConstraints.EMPTY);
            while (ori.hasNext()){
                OutboundRequest or = ori.next();
                ObjectOutputStream oos = new ObjectOutputStream(
                    or.getRequestOutputStream());
                oos.writeInt(1);
                oos.close();
            }
        } catch (Exception e2) {
            //Expected exception
            log.finest("Expected exception " + e2.getMessage());
        }
        if (dispatcher.dispatchCalled()!=-1){
            throw new TestException("Exception from the "
                + "dispatcher was not propagated");
        }
        dispatcher.accept();
        try {
            OutboundRequestIterator ori =
                e.newRequest(InvocationConstraints.EMPTY);
            while (ori.hasNext()) {
               OutboundRequest or = ori.next();
               ObjectOutputStream oos = new ObjectOutputStream(
               or.getRequestOutputStream());
               oos.writeInt(2);
View Full Code Here

    public void run() throws Exception {
        //Start a listen opertation
        ServerSocket ss = new ServerSocket(getPort());
        acceptOneConnection(ss);
        Endpoint ep = getEndpoint();
        openClientConnection(ep);
        Socket connection = getConnection();
        if (connection==null) {
            throw new TestException("Unable to establish"
                + "client/server connection");
View Full Code Here

        //obtain a ServerEndpoint and verify that the addListenEndpoint
        //is called on the ListenContext specified and the expected number
        //of ListenEndpoints are passed in to the context.
        SETContext lc = new SETContext();
        ServerEndpoint se = getServerEndpoint();
        Endpoint e = se.enumerateListenEndpoints(lc);
        boolean exceptionThrown = false;
        log.finest("Call to enumerateListeEndpoints returns " + e);
        Integer expected = (Integer) getConfigObject(Integer.class,
            "expectedListenEndpoints");
        ArrayList endpoints = lc.getEndpoints();
        if (expected.intValue() != endpoints.size()) {
            throw new TestException(
                "ServerEndpoint.enumerateListenEndpoints did not return"
                + "the expected number of ListenEndpoints.  Expected "
                + expected.intValue() + " but received "
                + endpoints.size());
        }
        //Verify that the returned endpoint is serializable
        if (!(e instanceof Serializable)){
            throw new TestException("The Endpoint returned by"
                + " ServerEndpoint.enumerateListenEndpoints is not"
                + " serializable");
        }

        //Verify that an outbound request can be obtained from the Endpoint
        OutboundRequestIterator ori =
            e.newRequest(InvocationConstraints.EMPTY);
        int response = 0;
        while (ori.hasNext()) {
            //Verify that the outbound request can be used to communicate
            //with the server side of the connection
            OutboundRequest or = ori.next();
            ObjectOutputStream oos =
                new ObjectOutputStream(or.getRequestOutputStream());
            oos.writeInt(this.hashCode());
            oos.close();
            ObjectInputStream ois = new ObjectInputStream(
                or.getResponseInputStream());
            response = ois.readInt();
            ois.close();
            //Verify UnsupportedOperationException
            ArrayList al = new ArrayList();
            al.add(new Object());
            Collection uc = Collections.unmodifiableCollection(al);
            exceptionThrown = false;
            try {
                uc.add(new Object());
                //This is an implementation specific check
                //comment code line above this comment if implementation
                //is expected to populate the passed in context
                or.populateContext(uc);
            } catch (UnsupportedOperationException uoe) {
                //This exception would only occur if one of the
                //JERI layers attempts to write context information
                //to the collection
                exceptionThrown = true;
            }
            if (!exceptionThrown){
                throw new TestException("Passing an unmodifiable"
                    + " collection to populateContext does not result"
                    + " in UnsupportedOperationException");
            }
            //Verify idempotency of input/output streams
            InputStream i1 = or.getResponseInputStream();
            InputStream i2 = or.getResponseInputStream();
            OutputStream o1 = or.getRequestOutputStream();
            OutputStream o2 = or.getRequestOutputStream();
            if (o1!=o2||i1!=i2) {
                throw new TestException("Idempotency of streams"
                    + " is not maintained");
            }
        }

        //Verify NoSuchElementException
        exceptionThrown = false;
        try {
            ori.next();
        } catch (NoSuchElementException nse) {
            exceptionThrown = true;
        }
        if (!exceptionThrown) {
            throw new TestException("Calling next on an iterator"
                + " that has returned false from hasNext does not throw"
                + " NoSuchElementException");
        }

        Iterator it = endpoints.iterator();
        while(it.hasNext()) {
            EndpointHolder eph = (EndpointHolder) it.next();
            SETRequestHandler rh = (SETRequestHandler)
                eph.getRequestHandler();
            if (response != rh.hashCode()){
                throw new TestException("The response received"
                    + "does not match the response sent by the server"
                    + "side of the connection.  Server sent "
                    + rh.hashCode() + ", but the client got " + response);
            }
            ArrayList requests = rh.getRequests();
            if (requests.size()!=1){
                throw new TestException("The RequestDisptcher"
                    + " received the incorrect number of requests.  "
                    + "Expected 1 and received " + requests.size());
            }
            Iterator requestIterator = requests.iterator();
            while (requestIterator.hasNext()){
                Integer value = (Integer) requestIterator.next();
                if (value.intValue()!=this.hashCode()){
                    throw new TestException("The data read from"
                        + " the InboundRequest does not match the data"
                        + " written to the OutboundRequest.  Wrote "
                        + this.hashCode() + " read " + value);
                }
            }
            ServerEndpoint.ListenHandle lh = eph.getListenHandle();
            //Close the listen operation
            lh.close();
        }
        //Verify that new requests are not received after close has
        //been called on the ListenHandle
        try {
            ori = e.newRequest(InvocationConstraints.EMPTY);
            while (ori.hasNext()) {
                OutboundRequest or = ori.next();
                ObjectOutputStream oos =
                    new ObjectOutputStream(or.getRequestOutputStream());
                oos.writeInt(this.hashCode());
View Full Code Here

TOP

Related Classes of net.jini.jeri.Endpoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.