Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *      Copyright (C) 2012 DataStax Inc.
   *
   *   Licensed 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 com.datastax.driver.core;
 
 
 
Internal implementation of ResultSetFuture.
 
 
     private static final Logger logger = LoggerFactory.getLogger(ResultSetFuture.class);
 
     private final SessionManager session;
     private final Message.Request request;
     private volatile RequestHandler handler;
 
     DefaultResultSetFuture(SessionManager sessionMessage.Request request) {
         this. = session;
         this. = request;
     }
 
     @Override
     public void register(RequestHandler handler) {
         this. = handler;
     }
 
     @Override
     public Message.Request request() {
         return ;
     }
 
     @Override
     public void onSet(Connection connectionMessage.Response responseExecutionInfo infolong latency) {
         try {
             switch (response.type) {
                 case :
                     ResultMessage rm = (ResultMessage)response;
                     switch (rm.kind) {
                         case :
                             // propagate the keyspace change to other connections
                             ..setKeyspace(((ResultMessage.SetKeyspace)rm).);
                             set(ArrayBackedResultSet.fromMessage(rminfo));
                             break;
                         case :
                             ResultMessage.SchemaChange scc = (ResultMessage.SchemaChange)rm;
                             ResultSet rs = ArrayBackedResultSet.fromMessage(rminfo);
                             switch (scc.change) {
                                 case :
                                     if (scc.columnFamily.isEmpty()) {
                                         ...refreshSchema(connectionDefaultResultSetFuture.thisrsnullnull);
                                     } else {
                                         ...refreshSchema(connectionDefaultResultSetFuture.thisrsscc.keyspacenull);
                                     }
                                     break;
                                 case :
                                     if (scc.columnFamily.isEmpty()) {
                                         // If that the one keyspace we are logged in, reset to null (it shouldn't really happen but ...)
                                         // Note: Actually, Cassandra doesn't do that so we don't either as this could confuse prepared statements.
                                         // We'll add it back if CASSANDRA-5358 changes that behavior
                                         //if (scc.keyspace.equals(session.poolsState.keyspace))
                                         //    session.poolsState.setKeyspace(null);
                                         ...refreshSchema(connectionDefaultResultSetFuture.thisrsnullnull);
                                     } else {
                                         ...refreshSchema(connectionDefaultResultSetFuture.thisrsscc.keyspacenull);
                                     }
                                     break;
                                 case :
                                     if (scc.columnFamily.isEmpty()) {
                                         ...refreshSchema(connectionDefaultResultSetFuture.thisrsscc.keyspacenull);
                                     } else {
                                         ...refreshSchema(connectionDefaultResultSetFuture.thisrsscc.keyspacescc.columnFamily);
                                     }
                                     break;
                                 default:
                                    .info("Ignoring unknown schema change result");
                                    break;
                            }
                            break;
                        default:
                            set(ArrayBackedResultSet.fromMessage(rminfo));
                            break;
                    }
                    break;
                case :
                    setException(convertException(((ErrorMessage)response).));
                    break;
                default:
                    // This mean we have probably have a bad node, so defunct the connection
                    connection.defunct(new ConnectionException(connection.address, String.format("Got unexpected %s response"response.type)));
                    setException(new DriverInternalError(String.format("Got unexpected %s response from %s"response.typeconnection.address)));
                    break;
            }
        } catch (RuntimeException e) {
            // If we get a bug here, the client will not get it, so better forwarding the error
            setException(new DriverInternalError("Unexpected error while processing response from " + connection.addresse));
        }
    }
    @Override
    public void onSet(Connection connectionMessage.Response responselong latency) {
        // This is only called for internal calls (i.e, when the callback is not wrapped in ResponseHandler),
        // so don't bother with ExecutionInfo.
        onSet(connectionresponsenulllatency);
    }
    @Override
    public void onException(Connection connectionException exceptionlong latency) {
        setException(exception);
    }
    @Override
    public void onTimeout(Connection connectionlong latency) {
        // This is only called for internal calls (i.e, when the callback is not wrapped in ResponseHandler).
        // So just set an exception for the final result, which should be handled correctly by said internal call.
        setException(new ConnectionException(connection.address"Operation Timeouted"));
    }
    public ResultSet getUninterruptibly() {
        try {
            return Uninterruptibles.getUninterruptibly(this);
        } catch (ExecutionException e) {
            throw extractCauseFromExecutionException(e);
        }
    }
    public ResultSet getUninterruptibly(long timeoutTimeUnit unitthrows TimeoutException {
        try {
            return Uninterruptibles.getUninterruptibly(thistimeoutunit);
        } catch (ExecutionException e) {
            throw extractCauseFromExecutionException(e);
        }
    }
    @Override
    public boolean cancel(boolean mayInterruptIfRunning) {
        if (!super.cancel(mayInterruptIfRunning))
            return false;
        .cancel();
        return true;
    }
        // We could just rethrow e.getCause(). However, the cause of the ExecutionException has likely been
        // created on the I/O thread receiving the response. Which means that the stacktrace associated
        // with said cause will make no mention of the current thread. This is painful for say, finding
        // out which execute() statement actually raised the exception. So instead, we re-create the
        // exception.
        if (e.getCause() instanceof DriverException)
            throw ((DriverException)e.getCause()).copy();
        else
            throw new DriverInternalError("Unexpected exception thrown"e.getCause());
    }
    static void extractCause(Throwable cause) {
        // Same as above
        if (cause instanceof DriverException)
            throw ((DriverException)cause).copy();
        throw new DriverInternalError("Unexpected exception thrown"cause);
    }
        switch (te.code()) {
            case :
                return new DriverInternalError("An unexpected error occured server side: " + te.getMessage());
            case :
                return new DriverInternalError("An unexpected protocol error occured. This is a bug in this library, please report: " + te.getMessage());
            case :
                return new UnavailableException(ConsistencyLevel.from(ue.consistency), ue.requiredue.alive);
            case :
                return new DriverInternalError("Queried host was overloaded; this shouldn't happen, another node should have been tried");
            case :
                return new DriverInternalError("Queried host was boostrapping; this shouldn't happen, another node should have been tried");
            case :
                return new TruncateException(te.getMessage());
            case :
                return new WriteTimeoutException(ConsistencyLevel.from(wte.consistency), WriteType.from(wte.writeType), wte.receivedwte.blockFor);
            case :
                return new ReadTimeoutException(ConsistencyLevel.from(rte.consistency), rte.receivedrte.blockForrte.dataPresent);
            case :
                return new SyntaxError(te.getMessage());
            case :
                return new UnauthorizedException(te.getMessage());
            case :
                return new InvalidQueryException(te.getMessage());
            case :
                return new InvalidConfigurationInQueryException(te.getMessage());
            case :
                return new AlreadyExistsException(aee.ksNameaee.cfName);
            default:
                return new DriverInternalError("Unknown error return code: " + te.code());
        }
    }
New to GrepCode? Check out our FAQ X