@Override public synchronized Session getQueueMessageSession() { if ( queueMessageSession == null || queueMessageSession.isClosed() ) { queueMessageSession = dataStaxCluster.getApplicationLocalSession(); } return queueMessageSession; } }
mCallback = new Session.StatusCallback() {...}; // the code you already have Session.OpenRequest request = new Session.OpenRequest(mContext); request.setPermissions(Arrays.asList("email", "user_birthday")); request.setCallback(mCallback ); // get active session Session mFacebookSession = Session.getActiveSession(); if (mFacebookSession == null || mFacebookSession.isClosed()) { mFacebookSession = new Session(mContext); Session.setActiveSession(mFacebookSession); } mFacebookSession.openForRead(request);
@Override public synchronized Session getApplicationSession() { if ( applicationSession == null || applicationSession.isClosed() ) { applicationSession = dataStaxCluster.getApplicationSession(); } return applicationSession; }
/** * Logout From Facebook */ public static void callFacebookLogout(Context context) { Session session = Session.getActiveSession(); if (session != null) { if (!session.isClosed()) { session.closeAndClearTokenInformation(); //clear your preferences if saved } } else { session = new Session(context); Session.setActiveSession(session); session.closeAndClearTokenInformation(); //clear your preferences if saved } }
@Override public synchronized Session getClusterSession(){ // always grab cluster from getCluster() in case it was prematurely closed if ( clusterSession == null || clusterSession.isClosed() ){ int retries = 3; int retryCount = 0; while ( retryCount < retries){ try{ retryCount++; clusterSession = getCluster().connect(); break; }catch(NoHostAvailableException e){ if(retryCount == retries){ throw e; } try { Thread.sleep(1000); } catch (InterruptedException ie) { // swallow } } } } return clusterSession; }
/** * {@inheritDoc} */ @Override public synchronized Session connect() throws NoHostAvailableException { if (isDisconnected()) { LOG.info("Connected to cluster: {}", cluster.getClusterName()); for (Host host : getAllHosts()) LOG.info("Datacenter: {}; Host: {}; Rack: {}", host.getDatacenter(), host.getAddress(), host.getRack()); LOG.info("Connect to cluster using keyspace %s", keyspace); session = cluster.connect(keyspace); } else { LOG.warn("{} - Already connected to cluster: {}", getExecutorName(), cluster.getClusterName()); } if (session.isClosed()) { LOG.warn("Session has been closed - create new one!"); this.session = cluster.newSession(); } return session; }
/** Closes Cassandra driver session. */ public static void closeSession(Session driverSes) { if (driverSes == null) return; Cluster cluster = driverSes.getCluster(); if (!driverSes.isClosed()) U.closeQuiet(driverSes); if (!cluster.isClosed()) U.closeQuiet(cluster); }
@Override public synchronized Session getApplicationSession(){ // always grab cluster from getCluster() in case it was prematurely closed if ( applicationSession == null || applicationSession.isClosed() ){ int retries = 3; int retryCount = 0; while ( retryCount < retries){ try{ retryCount++; applicationSession = getCluster().connect( CQLUtils.quote( cassandraConfig.getApplicationKeyspace() ) ); break; }catch(NoHostAvailableException e){ if(retryCount == retries){ throw e; } try { Thread.sleep(1000); } catch (InterruptedException ie) { // swallow } } } } return applicationSession; }
@Override public synchronized Session getApplicationLocalSession(){ // always grab cluster from getCluster() in case it was prematurely closed if ( queueMessageSession == null || queueMessageSession.isClosed() ){ int retries = 3; int retryCount = 0; while ( retryCount < retries){ try{ retryCount++; queueMessageSession = getCluster().connect( CQLUtils.quote( cassandraConfig.getApplicationLocalKeyspace() ) ); break; }catch(NoHostAvailableException e){ if(retryCount == retries){ throw e; } try { Thread.sleep(1000); } catch (InterruptedException ie) { // swallow } } } } return queueMessageSession; }
@Override public boolean closed() { if (this.session == null) { this.tryOpen(); } return this.session == null ? true : this.session.isClosed(); }
@Override public boolean isClosed() { return session.isClosed(); }
protected void clearKeyspace() { // Drop keyspace with non-keyspace-session Statement stmt = SchemaBuilder.dropKeyspace(this.keyspace).ifExists(); LOG.debug("Drop keyspace: {}", stmt); Session session = this.cluster().connect(); try { session.execute(stmt); } finally { if (!session.isClosed()) { session.close(); } } }
protected void initKeyspace() { // Replication strategy: SimpleStrategy or NetworkTopologyStrategy String strategy = this.conf.get(CassandraOptions.CASSANDRA_STRATEGY); // Replication factor int factor = this.conf.get(CassandraOptions.CASSANDRA_REPLICATION); Map<String, Object> replication = new HashMap<>(); replication.putIfAbsent("class", strategy); replication.putIfAbsent("replication_factor", factor); Statement stmt = SchemaBuilder.createKeyspace(this.keyspace) .ifNotExists().with() .replication(replication); // Create keyspace with non-keyspace-session LOG.debug("Create keyspace: {}", stmt); Session session = this.cluster().connect(); try { session.execute(stmt); } finally { if (!session.isClosed()) { session.close(); } } }
/** * {@inheritDoc} */ @Override public boolean isClosed() { return (session == null || session.isClosed()); }
/** {@inheritDoc} */ @Override public boolean isClosed() { return mProxy.isClosed(); }
@Override public boolean isConnected() { try { return !session.isClosed(); } catch (DriverException ex) { throw new RuntimeException("closing database resource", ex); } } }
@Override public boolean isConnected() { Session session = this.cassandraHolder.session.get(); if (session == null) { return false; } else { return !session.isClosed(); } }
/** * Null-safe operation to determine whether the Cassandra {@link Session} is connected or not. * * @return a boolean value indicating whether the Cassandra {@link Session} is connected. * @see com.datastax.driver.core.Session#isClosed() * @see #getObject() */ public boolean isConnected() { Session session = getObject(); return !(session == null || session.isClosed()); }
public void connectFacebook() { Session session = Session.getActiveSession(); if (!session.isOpened() && !session.isClosed()) { session.openForRead(new Session.OpenRequest(this) .setCallback(statusCallback)); } else { Session.openActiveSession(this, true, statusCallback); } }
@Override public void close() { if (!cluster.isClosed()) { cluster.close(); } if (!session.isClosed()) { session.close(); } }