Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * 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 software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.as.test.integration.domain.management.util;
 
 
 import java.net.URI;
 
 import static java.security.AccessController.doPrivileged;

Shared test configuration where all org.jboss.as.controller.client.ModelControllerClients share a common org.jboss.remoting3.Endpoint and java.util.concurrent.Executor.

Author(s):
Emanuel Muckenhuber
 
 public class DomainControllerClientConfig implements Closeable {
 
     private static final String ENDPOINT_NAME = "domain-client-mgmt-endpoint";
 
     private static final AtomicInteger executorCount = new AtomicInteger();
         final ThreadGroup group = new ThreadGroup("domain-mgmt-client-thread");
         final ThreadFactory threadFactory = new JBossThreadFactory(group.null"%G " + .incrementAndGet() + "-%t"nullnulldoPrivileged(GetAccessControlContextAction.getInstance()));
         return new ThreadPoolExecutor(4, 4, 30L, .new LinkedBlockingQueue<Runnable>(256), threadFactory);
     }
 
     private final Endpoint endpoint;
     private final ExecutorService executorService;
     private final boolean destroyExecutor;
 
     DomainControllerClientConfig(final Endpoint endpointfinal ExecutorService executorServicefinal boolean destroyExecutor) {
         this. = endpoint;
         this. = executorService;
         this. = destroyExecutor;
     }

    
Create a connection wrapper.

Parameters:
connectionURI the connection URI
callbackHandler the callback handler
Returns:
the connection wrapper
Throws:
java.io.IOException
 
     DomainTestConnection createConnection(final URI connectionURIfinal CallbackHandler callbackHandlerthrows IOException {
         final ProtocolChannelClient.Configuration configuration = new ProtocolChannelClient.Configuration();
         configuration.setEndpoint();
         configuration.setUri(connectionURI);
         final ProtocolChannelClient client = ProtocolChannelClient.create(configuration);
         return new DomainTestConnection(clientcallbackHandler);
     }
 
     @Override
     public void close() throws IOException {
         if() {
             .shutdown();
         }
         if( != nulltry {
             .close();
         } catch (IOException e) {
             // ignore
         }
         if() {
            .shutdownNow();
        }
    }
    public static DomainControllerClientConfig create() throws IOException {
        return create(createDefaultExecutor(), true);
    }
    public static DomainControllerClientConfig create(final ExecutorService executorServicethrows IOException {
        return create(executorServicefalse);
    }
    static DomainControllerClientConfig create(final ExecutorService executorServiceboolean destroyExecutorthrows IOException {
        final Endpoint endpoint = Remoting.createEndpoint(.);
        endpoint.addConnectionProvider("remote"new RemoteConnectionProviderFactory(), .);
        return new DomainControllerClientConfig(endpointexecutorServicedestroyExecutor);
    }
New to GrepCode? Check out our FAQ X