/*
(non-Javadoc)

@see
com.impetus.kundera.configure.schema.api.AbstractSchemaManager#initiateClient
()
512378
@Override
    protected boolean initiateClient()
    {
        String message = null;
        for (String host : hosts)
        {
            vaildateHostPort(host, port);
            Configuration hadoopConf = new Configuration();
            hadoopConf.set("hbase.master", host + ":" + port);
            conn = HBasePropertyReader.hsmd.getDataStore() != null ? HBasePropertyReader.hsmd.getDataStore()
                    .getConnection() : null;
            if (conn != null && conn.getProperties() != null)
            {
                String zookeeperHost = conn.getProperties().getProperty("hbase.zookeeper.quorum").trim();
                String zookeeperPort = conn.getProperties().getProperty("hbase.zookeeper.property.clientPort").trim();
                vaildateHostPort(zookeeperHost, zookeeperPort);
                hadoopConf.set("hbase.zookeeper.quorum", zookeeperHost != null ? zookeeperHost : host);
                hadoopConf.set("hbase.zookeeper.property.clientPort", zookeeperPort != null ? zookeeperPort
                        : DEFAULT_ZOOKEEPER_PORT);
            }
            else
            {
                hadoopConf.set("hbase.zookeeper.quorum", host);
                hadoopConf.set("hbase.zookeeper.property.clientPort", DEFAULT_ZOOKEEPER_PORT);
            }
            Configuration conf = HBaseConfiguration.create(hadoopConf);
            try
            {
                Connection connection = ConnectionFactory.createConnection(conf);
                admin = (HBaseAdmin) connection.getAdmin();
                return true;
            }
            catch (MasterNotRunningException mnre)
            {
                message = mnre.getMessage();
                logger.error("Master not running exception, Caused by:", mnre);
            }
            catch (ZooKeeperConnectionException zkce)
            {
                message = zkce.getMessage();
                logger.error("Unable to connect to zookeeper, Caused by:", zkce);
            }
            catch (IOException ioe)
            {
                message = ioe.getMessage();
                logger.error("I/O exception, Caused by:", ioe);
            }
        }
        throw new SchemaGenerationException("Master not running exception, Caused by:" + message);
    }
355337
protected void configureClient(final BaseClient client, final Pac4jBaseClientProperties props) {
        val cname = props.getClientName();
        if (StringUtils.isNotBlank(cname)) {
            client.setName(cname);
        } else {
            val className = client.getClass().getSimpleName();
            val genName = className.concat(RandomStringUtils.randomNumeric(2));
            client.setName(genName);
            LOGGER.warn("Client name for [{}] is set to a generated value of [{}]. "
                + "Consider defining an explicit name for the delegated provider", className, genName);
        }
        val customProperties = client.getCustomProperties();
        customProperties.put(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_AUTO_REDIRECT, props.isAutoRedirect());
        if (StringUtils.isNotBlank(props.getPrincipalAttributeId())) {
            customProperties.put(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_PRINCIPAL_ATTRIBUTE_ID, props.getPrincipalAttributeId());
        }
    }
974787
@Override
    void start() throws InitializationException {
        if (hsqlServer == null) {
            hsqlServer = new Server();
            hsqlServer.setLogWriter(null);
            hsqlServer.setSilent(true);
            hsqlServer.setDatabaseName(0, EMBEDED_DB_NAME);
            hsqlServer.setDatabasePath(0, "file:" + EMBEDED_DB_FILE_NAME + ";user=" + getUname() + ";password="
                    + getPassword());
            hsqlServer.start();
        }
    }
83234
private function initializeClient($url, ClientInterface $client = null)
    {
        if ($client) {
            $this->client = $client;
        } else {
            $this->client = new LocalClient($url);
        }
    }
363732
public static void initialize(String token) {
    if (token == null) {
      throw new IllegalArgumentException("Token should be defined.");
    }
    initialize(new ClientProperties(token, null, null));
  }
1121294
@Override
	protected final void remoteInit() throws JMSException
    {
        CreateDurableSubscriberQuery query = new CreateDurableSubscriberQuery();
        query.setSessionId(session.getId());
        query.setConsumerId(id);
        query.setTopic((Topic)destination);
        query.setMessageSelector(messageSelector);
        query.setNoLocal(noLocal);
        query.setName(subscriptionName);
        transportEndpoint.blockingRequest(query);
    }
424249
public SoapClientActionBuilder client(String soapClient) {
		SoapClientActionBuilder clientAction = new SoapClientActionBuilder(action, soapClient)
				.withApplicationContext(applicationContext);
		return clientAction;
	}
800402
@Override
    protected boolean initiateClient()
    {
        for (String host : hosts)
        {
            if (host == null || !StringUtils.isNumeric(port) || port.isEmpty())
            {
                logger.error("Host or port should not be null / port should be numeric");
                throw new IllegalArgumentException("Host or port should not be null / port should be numeric");
            }
            try
            {
                connection = r.connection().hostname(host).port(Integer.parseInt(port)).connect();
            }
            catch (Exception e)
            {
                logger.error("Database host/port cannot be resolved, Caused by: " + e.getMessage());
                throw new SchemaGenerationException("Database host/port cannot be resolved, Caused by: " + e.getMessage());
            }
        }
        return true;
    }
1200650
@Override
    @Deprecated
    protected void initializeInternal() throws RepositoryException {
        this.databaseClient = DatabaseClientFactory.newClient(host,port,user,password,DatabaseClientFactory.Authentication.valueOf(auth));
        this.client = new MarkLogicClient(databaseClient);
    }
83032
@Override
    protected Client instantiateClient(String persistenceUnit)
    {
        return new KuduDBClient(kunderaMetadata, indexManager, reader, externalProperties, persistenceUnit,
                this.kuduClient, this.clientMetadata);
    }
1046840
static ExecutorService startClientService(SystemMain system, ClientType clientType, AtomicInteger jobCounter) {
        switch (clientType) {
            case ALERT:
                return startAlertClientService(system, jobCounter);
            case COMMIT_SCHEMA:

                /* Alpha feature, not currently supported. */
                return startCommitSchemaClientService(system, jobCounter);
            case COMMIT_ANNOTATIONS:
                return startCommitAnnotationsClientService(system, jobCounter);
            case PROCESS_QUERIES:
                return startProcessMetricsClientService(system, jobCounter);
            default:
                return startCommitMetricsClientService(system, jobCounter);
        }
    }
566797
protected boolean initiateClient()
    {
        for (String host : hosts)
        {
            if (host == null || !StringUtils.isNumeric(port) || port.isEmpty())
            {
                logger.error("Host or port should not be null / port should be numeric");
                throw new IllegalArgumentException("Host or port should not be null / port should be numeric");
            }

            List<MongoCredential> credentials = MongoDBUtils.fetchCredentials(puMetadata.getProperties(),
                    externalProperties);
            ServerAddress addr;
            try
            {
                addr = new ServerAddress(host, Integer.parseInt(port));
            }
            catch (NumberFormatException ex)
            {
                throw new SchemaGenerationException(ex);
            }

            mongo = new MongoClient(addr, credentials);
            db = mongo.getDB(databaseName);
            return true;
        }
        return false;
    }
1113180
public static ClientInterface create(
            HostMessenger messenger,
            CatalogContext context,
            ReplicationRole replicationRole,
            Cartographer cartographer,
            InetAddress clientIntf,
            int clientPort,
            InetAddress adminIntf,
            int adminPort,
            SslContext SslContext) throws Exception {

        /*
         * Construct the runnables so they have access to the list of connections
         */
        final ClientInterface ci = new ClientInterface(
                clientIntf, clientPort, adminIntf, adminPort, context, messenger, replicationRole, cartographer,
                SslContext);

        return ci;
    }
327956
private static ClientFactory instantiateClientFactory(String persistenceUnit, Map<String, Object> puProperties,
            final KunderaMetadata kunderaMetadata)
    {
        ClientFactory clientFactory = null;
        logger.info("Initializing client factory for: " + persistenceUnit);
        PersistenceUnitMetadata persistenceUnitMetadata = kunderaMetadata.getApplicationMetadata()
                .getPersistenceUnitMetadata(persistenceUnit);
        String kunderaClientFactory = puProperties != null ? (String) puProperties
                .get(PersistenceProperties.KUNDERA_CLIENT_FACTORY) : null;
        if (kunderaClientFactory == null)
        {
            kunderaClientFactory = persistenceUnitMetadata.getProperties().getProperty(
                    PersistenceProperties.KUNDERA_CLIENT_FACTORY);
        }

        if (kunderaClientFactory == null)
        {
            throw new ClientResolverException(
                    "<kundera.client.lookup.class> is missing from persistence.xml, please provide specific client factory. e.g., <property name=\"kundera.client.lookup.class\" value=\"com.impetus.client.cassandra.pelops.PelopsClientFactory\" />");
        }
        try
        {
            clientFactory = (ClientFactory) Class.forName(kunderaClientFactory).newInstance();

            Method m = GenericClientFactory.class.getDeclaredMethod("setPersistenceUnit", String.class);
            if (!m.isAccessible())
            {
                m.setAccessible(true);
            }

            m.invoke(clientFactory, persistenceUnit);

            m = GenericClientFactory.class.getDeclaredMethod("setExternalProperties", Map.class);
            if (!m.isAccessible())
            {
                m.setAccessible(true);
            }

            m.invoke(clientFactory, puProperties);
            
            m = GenericClientFactory.class.getDeclaredMethod("setKunderaMetadata", KunderaMetadata.class);
            if (!m.isAccessible())
            {
                m.setAccessible(true);
            }

            m.invoke(clientFactory, kunderaMetadata);
            
        }
        catch (InstantiationException e)
        {
            onError(e);
        }
        catch (IllegalAccessException e)
        {
            onError(e);
        }
        catch (ClassNotFoundException e)
        {
            onError(e);
        }
        catch (SecurityException e)
        {
            onError(e);
        }
        catch (NoSuchMethodException e)
        {
            onError(e);
        }
        catch (IllegalArgumentException e)
        {
            onError(e);
        }
        catch (InvocationTargetException e)
        {
            onError(e);
        }

        if (clientFactory == null)
        {
            logger.error("Client Factory Not Configured For Specified Client Type : ");
            throw new ClientResolverException("Client Factory Not Configured For Specified Client Type.");
        }
        logger.info("Finishing factory initialization");
        return clientFactory;
    }
465038
protected void initializeClient(JestClient client, String indexName, String defaultIndexName) {
        try {
            client.execute(new Health.Builder().build());
            Action<JestResult> action = new IndicesExists.Builder(indexName).build();
            // There was occasions where a race occurred here when multiple threads try to
            // create the index simultaneously. This caused a non-fatal, but annoying, exception.
            synchronized(AbstractClientFactory.class) {
                JestResult result = client.execute(action);
                if (!result.isSucceeded()) {
                    createIndex(client, indexName, defaultIndexName + "-settings.json"); //$NON-NLS-1$
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
81754
@Override
  public void addClient(ClientData clientData) {
    clientsData.put(clientData.id, clientData);
    dispatcher.assignClient(clientData.id);
    LOG.info("Succesfully added client " + clientData);
    metrics.numRegisteredClients.set(clientsData.size());
  }
268892
public void setClient(String client) {
        if (meta == null) {
            meta = new EventMeta();
        }
        meta.setClient(client);
    }