Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8177585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:32:52+00:00 2026-06-06T23:32:52+00:00

I am unable to access Casandra using Hector. Following is the code import java.util.Arrays;

  • 0

I am unable to access Casandra using Hector. Following is the code

 import java.util.Arrays;
 import java.util.List;
 import me.prettyprint.cassandra.service.CassandraHostConfigurator;
 import me.prettyprint.cassandra.service.ThriftCluster;
 import me.prettyprint.cassandra.service.ThriftKsDef;
 import me.prettyprint.hector.api.Cluster;
 import me.prettyprint.hector.api.Keyspace;
 import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
 import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
 import me.prettyprint.hector.api.factory.HFactory;
 import me.prettyprint.hector.api.mutation.Mutator;

 public class Hector {
 public static void main (String[] args){
boolean cfExists = false;
Cluster cluster = HFactory.getOrCreateCluster("mycluster", new                     CassandraHostConfigurator("host:9160"));
Keyspace keyspace = HFactory.createKeyspace("Keyspace1", cluster);
// first check if the key space exists
        KeyspaceDefinition keyspaceDetail = cluster.describeKeyspace("Keyspace1");
        // if not, create one
        if (keyspaceDetail == null) {

            CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("host:9160");
            ThriftCluster cassandraCluster = new ThriftCluster("mycluster", cassandraHostConfigurator);

            ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("Keyspace1", "base");
            cassandraCluster.addKeyspace(new ThriftKsDef("Keyspace1", "org.apache.cassandra.locator.SimpleStrategy", 1,
                    Arrays.asList(cfDef)));

        } else {

            // even if the key space exists, we need to check if the column family exists
            List<ColumnFamilyDefinition> columnFamilyDefinitions = keyspaceDetail.getCfDefs();
            for (ColumnFamilyDefinition def : columnFamilyDefinitions)    {
                String columnFamilyName = def.getName();
                if (columnFamilyName.equals("tcs_im"))
                    cfExists = true;
            }
        }
 }
 } 

Encountering following error

log4j:WARN No appenders could be found for logger (me.prettyprint.cassandra.connection.CassandraHostRetryService).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread “main” java.lang.IllegalAccessError: tried to access class me.prettyprint.cassandra.service.JmxMonitor from class me.prettyprint.cassandra.connection.HConnectionManager
at me.prettyprint.cassandra.connection.HConnectionManager.(HConnectionManager.java:78)
at me.prettyprint.cassandra.service.AbstractCluster.(AbstractCluster.java:69)
at me.prettyprint.cassandra.service.AbstractCluster.(AbstractCluster.java:65)
at me.prettyprint.cassandra.service.ThriftCluster.(ThriftCluster.java:17)
at me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:176)
at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:155)
at com.im.tcs.Hector.main(Hector.java:20)

Please help as to why is it happening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:32:54+00:00Added an answer on June 6, 2026 at 11:32 pm

    We use a CassandraConnection class as a convenience-class:

    import me.prettyprint.cassandra.connection.DynamicLoadBalancingPolicy;
    import me.prettyprint.cassandra.service.CassandraHostConfigurator;
    import me.prettyprint.cassandra.service.ExhaustedPolicy;
    import me.prettyprint.cassandra.service.OperationType;
    import me.prettyprint.hector.api.Cluster;
    import me.prettyprint.hector.api.HConsistencyLevel;
    import me.prettyprint.hector.api.Keyspace;
    import me.prettyprint.hector.api.factory.HFactory;
    
    import java.util.HashMap;
    import java.util.Map;
    
    /**
     * lazy connect
     */
    final class CassandraConnection {
    
        // Constants -----------------------------------------------------
    
        private static final String HOSTS = "localhost";
        private static final int PORT = "9160";
        private static final String CLUSTER_NAME = "myCluster";
        private static final int TIMEOUT = 500);
        private static final String KEYSPACE = "Keyspace1";
        private static final ConsistencyLevelPolicy CL_POLICY = new ConsistencyLevelPolicy();
    
        // Attributes ----------------------------------------------------
    
        private Cluster cluster;
        private volatile Keyspace keyspace;
    
        // Constructors --------------------------------------------------
    
        CassandraConnection() {}
    
        // Methods --------------------------------------------------------
    
        Cluster getCluster() {
            if (null == cluster) {
                CassandraHostConfigurator config = new CassandraHostConfigurator();
                config.setHosts(HOSTS);
                config.setPort(PORT);
                config.setUseThriftFramedTransport(true);
                config.setUseSocketKeepalive(true);
                config.setAutoDiscoverHosts(false);
                // maxWorkerThreads provides the throttling for us. So hector can be let to grow freely...
                config.setExhaustedPolicy(ExhaustedPolicy.WHEN_EXHAUSTED_GROW);
                config.setMaxActive(1000); // hack since ExhaustedPolicy doesn't work
                // suspend hosts if response is unacceptable for web response
                config.setCassandraThriftSocketTimeout(TIMEOUT);
                config.setUseHostTimeoutTracker(true);
                config.setHostTimeoutCounter(3);
                config.setLoadBalancingPolicy(new DynamicLoadBalancingPolicy());
    
                cluster = HFactory.createCluster(CLUSTER_NAME, config);
    
            }
            return cluster;
        }
    
        Keyspace getKeyspace() {
            if (null == keyspace) {
                keyspace = HFactory.createKeyspace(KEYSPACE, getCluster(), CL_POLICY);
            }
            return keyspace;
        }
    
        private static class ConsistencyLevelPolicy implements me.prettyprint.hector.api.ConsistencyLevelPolicy {
    
            @Override
            public HConsistencyLevel get(final OperationType op) {
                return HConsistencyLevel.ONE;
            }
    
            @Override
            public HConsistencyLevel get(final OperationType op, final String cfName) {
                return get(op);
            }
        }
    }
    

    Example of use:

    private final CassandraConnection conn = new CassandraConnection();
    
    SliceQuery<String, String, String> sliceQuery = HFactory.createSliceQuery(
                    conn.getKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
    sliceQuery.setColumnFamily("myColumnFamily");
    sliceQuery.setRange("", "", false, Integer.MAX_VALUE);
    sliceQuery.setKey("myRowKey");
    ColumnSlice<String, String> columnSlice = sliceQuery.execute().get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following error: Warning: fopen() [function.fopen]: Unable to access Archive-Report-Sat-Dec-2011 12-12-42.xls/var/www/vhosts/eample.com/httpdocs/_files/Archive-Report-Sat-Dec-2011
Unable to access WCF Service from Client machine I have three projects : WCF
I am unable to access a database table in rails. I am using ruby
I have the following, however I'm unable to access the database functions outside of
When trying to access the database, I am unable to access the column. I
I have a @property listOfSites declared in a class. I am unable to access
I try to access the MainContentBlock control from the aspx, but unable to do
Unable to cast object type System.Collections.Generic.List 1[NorthwindMVC3.Models.Product] to the type ofSystem.Collections.Generic.IEnumerator 1[NorthwindMVC3.Models.Product].\ public IEnumerator<Product>
I'm unable to execute the following prepared statement , PREPARE stmt FROM 'SELECT sb.id,sb.category,sb.make,sb.name,sb.pic,rs.slot
I'm getting an Unable to obtain public key for StrongNameKeyPair. exception using Newtonsoft's JsonConvert.SerializeObject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.