Github user satishd commented on a diff in the pull request:

    https://github.com/apache/storm/pull/827#discussion_r45037103
  
    --- Diff: 
external/storm-cassandra/src/main/java/org/apache/storm/cassandra/client/impl/DefaultClient.java
 ---
    @@ -0,0 +1,123 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.storm.cassandra.client.impl;
    +
    +import com.datastax.driver.core.Cluster;
    +import com.datastax.driver.core.Host;
    +import com.datastax.driver.core.Metadata;
    +import com.datastax.driver.core.Session;
    +import com.datastax.driver.core.exceptions.NoHostAvailableException;
    +import com.google.common.base.Preconditions;
    +import org.apache.storm.cassandra.client.SimpleClient;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.Closeable;
    +import java.io.Serializable;
    +import java.util.Set;
    +
    +/**
    + * Simple class to wrap cassandra {@link com.datastax.driver.core.Cluster} 
instance.
    + */
    +public class DefaultClient implements SimpleClient, Closeable, 
Serializable {
    +    
    +    private final static Logger LOG = 
LoggerFactory.getLogger(DefaultClient.class);
    +    
    +    private String keyspace;
    +
    +    private Cluster cluster;
    +    
    +    private Session session;
    +
    +    /**
    +     * Create a new {@link DefaultClient} instance.
    +     * 
    +     * @param cluster a cassandra cluster client.
    +     */
    +    public DefaultClient(Cluster cluster, String keyspace) {
    +        Preconditions.checkNotNull(cluster, "Cluster cannot be 'null");
    +        this.cluster = cluster;
    +        this.keyspace = keyspace;
    +        
    +    }
    +
    +    public Set<Host> getAllHosts() {
    +        Metadata metadata = getMetadata();
    +        return metadata.getAllHosts();
    +    }
    +
    +    public Metadata getMetadata() {
    +        return cluster.getMetadata();
    +    }
    +
    +
    +    private String getExecutorName() {
    +        Thread thread = Thread.currentThread();
    +        return thread.getName();
    +    }
    +    /**
    +     * {@inheritDoc}
    +     */
    +    @Override
    +    public synchronized Session connect() throws NoHostAvailableException {
    +        if( isDisconnected() ) {
    +            LOG.info(String.format("Connected to cluster: %s", 
cluster.getClusterName()));
    --- End diff --
    
    Can you replace String.format with LOG.info(String format, Object... 
arguments) as it does not build the string if the respective logging level is 
not enabled. It saves building strings unnecessarily. You may want to refactor 
it at other log usages.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to