Opens a Session to Cassandra and initializes the prepared statement.

@param taskNumber The number of the parallel instance.
@throws IOException Thrown, if the output could not be opened due to an
I/O problem.
191940
@Override
	public void open(int taskNumber, int numTasks) throws IOException {
		this.session = cluster.connect();
		this.prepared = session.prepare(insertQuery);
		this.callback = new FutureCallback<ResultSet>() {
			@Override
			public void onSuccess(ResultSet ignored) {
				onWriteSuccess(ignored);
			}

			@Override
			public void onFailure(Throwable t) {
				onWriteFailure(t);
			}
		};
	}
1126764
@Override
	protected void run() throws Exception {

		final String iterationId = getConfiguration().getIterationId();
		if (iterationId == null || iterationId.length() == 0) {
			throw new Exception("Missing iteration ID in the task configuration");
		}

		final String brokerID = createBrokerIdString(getEnvironment().getJobID(), iterationId ,
				getEnvironment().getTaskInfo().getIndexOfThisSubtask());

		final long iterationWaitTime = getConfiguration().getIterationWaitTime();
		final boolean shouldWait = iterationWaitTime > 0;

		final BlockingQueue<StreamRecord<OUT>> dataChannel = new ArrayBlockingQueue<StreamRecord<OUT>>(1);

		// offer the queue for the tail
		BlockingQueueBroker.INSTANCE.handIn(brokerID, dataChannel);
		LOG.info("Iteration head {} added feedback queue under {}", getName(), brokerID);

		// do the work
		try {
			@SuppressWarnings("unchecked")
			RecordWriterOutput<OUT>[] outputs = (RecordWriterOutput<OUT>[]) getStreamOutputs();

			// If timestamps are enabled we make sure to remove cyclic watermark dependencies
			if (isSerializingTimestamps()) {
				synchronized (getCheckpointLock()) {
					for (RecordWriterOutput<OUT> output : outputs) {
						output.emitWatermark(new Watermark(Long.MAX_VALUE));
					}
				}
			}

			while (running) {
				StreamRecord<OUT> nextRecord = shouldWait ?
					dataChannel.poll(iterationWaitTime, TimeUnit.MILLISECONDS) :
					dataChannel.take();

				if (nextRecord != null) {
					synchronized (getCheckpointLock()) {
						for (RecordWriterOutput<OUT> output : outputs) {
							output.collect(nextRecord);
						}
					}
				}
				else {
					// done
					break;
				}
			}
		}
		finally {
			// make sure that we remove the queue from the broker, to prevent a resource leak
			BlockingQueueBroker.INSTANCE.remove(brokerID);
			LOG.info("Iteration head {} removed feedback queue under {}", getName(), brokerID);
		}
	}
664589
private int preparedStatement(Cassandra.Client client)
        {
            Integer itemId = preparedStatements.get(client);
            if (itemId == null)
            {
                CqlPreparedResult result;
                try
                {
                    result = client.prepare_cql3_query(ByteBufferUtil.bytes(cql), Compression.NONE);
                }
                catch (InvalidRequestException e)
                {
                    throw new RuntimeException("failed to prepare cql query " + cql, e);
                }
                catch (TException e)
                {
                    throw new RuntimeException("failed to prepare cql query " + cql, e);
                }

                Integer previousId = preparedStatements.putIfAbsent(client, Integer.valueOf(result.itemId));
                itemId = previousId == null ? result.itemId : previousId;
            }
            return itemId;
        }
815481
@Override
    @FFDCIgnore(value = { RejectedExecutionException.class })
    public <T> T invokeAny(Collection<? extends Callable<T>> tasks, PolicyTaskCallback[] callbacks, long timeout,
                           TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        int taskCount = tasks.size();
        long stop = System.nanoTime() + unit.toNanos(timeout);
        long qWait, remaining;

        if (taskCount == 0) // JavaDoc doesn't specify what to do in this case. Match behavior of untimed invokeAny.
            throw new IllegalArgumentException();

        InvokeAnyLatch latch = new InvokeAnyLatch(taskCount);
        ArrayList<PolicyTaskFutureImpl<T>> futures = new ArrayList<PolicyTaskFutureImpl<T>>(taskCount);
        try {
            // create futures in advance, which gives the callback an opportunity to reject
            int t = 0;
            for (Callable<T> task : tasks) {
                remaining = stop - System.nanoTime();
                PolicyTaskCallback callback = callbacks == null ? null : callbacks[t++];
                PolicyExecutorImpl executor = callback == null ? this : (PolicyExecutorImpl) callback.getExecutor(this);
                long startTimeoutNS = callback == null ? startTimeout : callback.getStartTimeout(executor.startTimeout);
                PolicyTaskFutureImpl<T> taskFuture = new PolicyTaskFutureImpl<T>(executor, task, callback, startTimeoutNS, latch);
                futures.add(taskFuture);
                if (remaining <= 0)
                    throw new RejectedExecutionException(Tr.formatMessage(tc, "CWWKE1204.unable.to.invoke", taskFuture.getIdentifier(),
                                                                          taskCount - futures.size(), taskCount, timeout, unit));
            }

            // enqueue all tasks
            for (PolicyTaskFutureImpl<T> taskFuture : futures) {
                remaining = stop - System.nanoTime();

                // check if done before enqueuing more tasks
                if (latch.getCount() == 0)
                    break;

                if (remaining <= 0)
                    throw new RejectedExecutionException(Tr.formatMessage(tc, "CWWKE1204.unable.to.invoke", taskFuture.getIdentifier(),
                                                                          taskCount - futures.size(), taskCount, timeout, unit));
                qWait = taskFuture.executor.maxWaitForEnqueueNS.get();
                taskFuture.executor.enqueue(taskFuture,
                                            qWait < remaining ? qWait : remaining, // limit waiting to lesser of maxWaitForEnqueue and remaining time
                                            false); // never run on the current thread because it would prevent timeout
            }

            // wait for completion
            remaining = stop - System.nanoTime();
            return latch.await(remaining < 0 ? 0 : remaining, futures);
        } catch (RejectedExecutionException x) {
            if (x.getCause() instanceof InterruptedException)
                throw (InterruptedException) x.getCause();
            else
                throw x;
        } finally {
            for (Future<?> f : futures)
                f.cancel(true);
        }
    }
1134336
public void logMessageForTask(String taskId, String logMessage) {
        Preconditions.checkArgument(StringUtils.isNotBlank(taskId), "Task id cannot be blank");
        postForEntityWithRequestOnly("tasks/" + taskId + "/log", logMessage);
    }
185797
@SuppressWarnings("checkstyle:illegalcatch")
  public void beforeTaskStart() throws TaskStartHandlerFailure {
    LOG.log(Level.FINEST, "Sending TaskStart event to the registered event handlers.");
    for (final EventHandler<TaskStart> startHandler : this.taskStartHandlers) {
      try {
        startHandler.onNext(this.taskStart);
      } catch (final Throwable throwable) {
        throw new TaskStartHandlerFailure(startHandler, throwable);
      }
    }
    LOG.log(Level.FINEST, "Done sending TaskStart event to the registered event handlers.");
  }
394597
public int login(Task task, String strUserName, String strPassword, String strDomain)
    {
        boolean bCreateServer = false;
        if ((this.getProperty(DBParams.REMOTE_HOST) != null) && (this.getProperty(DBParams.REMOTE_HOST).length() > 0))
            bCreateServer = true;
        org.jbundle.thin.base.remote.RemoteTask remoteTask = (org.jbundle.thin.base.remote.RemoteTask)this.getRemoteTask(null, strUserName, bCreateServer);
        if (remoteTask != null)
            return super.login(task, strUserName, strPassword, strDomain); // Remote client - have server log me in
        else
        {   // If I'm not remote, I need to read the user info.
            Map<String,Object> mapDomainProperties = this.setDomainProperties(task, strDomain);
            this.setProperty(Params.USER_ID, null);
            this.setProperty(Params.USER_NAME, null);
            if (Utility.isNumeric(strUserName))
                this.setProperty(Params.USER_ID, strUserName);
            else
                this.setProperty(Params.USER_NAME, strUserName);
            if ((this.getProperty(Params.USER_ID) == null) || (this.getProperty(Params.USER_ID).length() == 0))
                if ((this.getProperty(Params.USER_NAME) == null) || (this.getProperty(Params.USER_NAME).length() == 0))
            {   // If user is not specified (either for no user, or logout), use the anonymous user
                Record recUserControl = null;
                if (m_systemRecordOwner != null)
                {   // Always
                    recUserControl = (Record)m_systemRecordOwner.getRecord(UserControlModel.USER_CONTROL_FILE);
                    if (recUserControl == null)
                        recUserControl = Record.makeRecordFromClassName(UserControlModel.THICK_CLASS, m_systemRecordOwner);
                    String strUserID = recUserControl.getField(UserControlModel.ANON_USER_INFO_ID).getString();
                    if ((strUserID == null) || (strUserID.length() == 0))
                        strUserID = DBConstants.ANON_USER_ID;
                    this.setProperty(Params.USER_ID, strUserID);
                }
            }
            if (this.readUserInfo(false, true) == true)
            {
                UserInfoModel recUserInfo = this.getUserInfo();
                if ((strPassword != null) && (strPassword.length() > 0))
                {
                    while (strPassword.endsWith("%3D")) {
                        strPassword = strPassword.substring(0, strPassword.length() - 3) + "="; // Often converted when passing URLs
                    }
                    if (!strPassword.equals(recUserInfo.getField(UserInfoModel.PASSWORD).toString()))
                    {
                        return task.setLastError(this.getString("User name and password do not match"));
                    }
                    // Create and save the remote authorization token.
                    String strToken = Long.toString((long)(Math.random() * Long.MAX_VALUE));
                    strToken = Base64.encode(strToken);
                    this.setProperty(DBParams.AUTH_TOKEN, strToken);
                    // todo(don) HACK - For now, authentication is the SHA password! See ServletTask/777
                    this.setProperty(DBParams.AUTH_TOKEN, strPassword);    // NO NO NO                    
                }

                Record recUserGroup = ((ReferenceField)recUserInfo.getField(UserInfoModel.USER_GROUP_ID)).getReference();
                String strSecurityMap = null;
                Map<String,Object> mapUserProperties = ((PropertiesField)recUserInfo.getField(UserInfoModel.PROPERTIES)).getProperties();
                Map<String,Object> mapGroupProperties = null;
                if (recUserGroup != null)
                {
                    strSecurityMap = recUserGroup.getField(UserGroupModel.ACCESS_MAP).toString();
                    mapGroupProperties = ((PropertiesField)recUserGroup.getField(UserGroupModel.PROPERTIES)).getProperties();
                }
                if (strSecurityMap == null)
                    strSecurityMap = DBConstants.BLANK;     // The signals the the user is signed on
                this.setProperty(Params.SECURITY_MAP, strSecurityMap);
                this.setProperty(Params.SECURITY_LEVEL, ((strPassword == null) || (strPassword.length() == 0)) ? Integer.toString(Constants.LOGIN_USER) : Integer.toString(Constants.LOGIN_AUTHENTICATED));
                if ((DBConstants.ANON_USER_ID.equals(recUserInfo.getField(UserInfoModel.ID).toString()))
                        || (recUserInfo == null))
                    this.setProperty(Params.SECURITY_LEVEL, Integer.toString(Constants.LOGIN_USER));   // Special case - If user is anonymous, level is always anonymous
                Map<String,Object> properties = new Hashtable<String,Object>();
                if (mapDomainProperties != null)
                    properties.putAll(mapDomainProperties);   // Merge the properties
                if (mapGroupProperties != null)
                    properties.putAll(mapGroupProperties);   // Merge the properties
                if (mapUserProperties != null)
                    properties.putAll(mapUserProperties);   // Merge the properties
                if (recUserInfo != null)
                {
                    this.setProperty(DBParams.USER_ID, recUserInfo.getField(UserInfoModel.ID).toString());
                    if (!recUserInfo.getField(UserInfoModel.USER_NAME).isNull())
                        this.setProperty(DBParams.USER_NAME, recUserInfo.getField(UserInfoModel.USER_NAME).toString());
                    if (properties != null)
                    {
                        properties.put(DBParams.USER_ID, recUserInfo.getField(UserInfo.ID).toString());
                        if (!recUserInfo.getField(UserInfoModel.USER_NAME).isNull())
                            properties.put(DBParams.USER_NAME, recUserInfo.getField(UserInfoModel.USER_NAME).toString());
                        if (this.getProperty(DBParams.AUTH_TOKEN) != null)
                            properties.put(DBParams.AUTH_TOKEN, this.getProperty(DBParams.AUTH_TOKEN));
                    }
                }
                m_systemRecordOwner.setProperties(properties);  // These are the user properties

                UserLogModel recUserLog = null;
                if (m_systemRecordOwner != null)
                {   // Always
                    recUserLog = (UserLogModel)m_systemRecordOwner.getRecord(UserLogModel.USER_LOG_FILE);
                    if (recUserLog == null)
                        recUserLog = (UserLogModel)Record.makeRecordFromClassName(UserLogModel.THICK_CLASS, m_systemRecordOwner);
                }
                if (recUserLog != null)
                    if (this.getProperty(DBParams.USER_ID) != null)
                        if (this.getProperty(DBParams.USER_ID).length() > 0)
                            if (!DBConstants.ANON_USER_ID.equals(this.getProperty(DBParams.USER_ID)))
                {
                    try {
                        int iUserID = Integer.parseInt(this.getProperty(DBParams.USER_ID));
                        int iUserLogTypeID = UserLogTypeModel.LOGIN;
                        String strMessage = "Login";
                        recUserLog.log(iUserID, iUserLogTypeID, strMessage);
                    } catch (NumberFormatException e) {
                        // Ignore
                    }
                }

                return Constants.NORMAL_RETURN;
            }
            else if (task != null)
                return task.setLastError(this.getString("User name and password do not match"));
            else
                return DBConstants.ERROR_RETURN;
        }
    }
1100054
@SuppressWarnings("unchecked")
	@Override
	public void initialize() {
		// grab a handle to the hash table from the iteration broker
		if (taskContext instanceof AbstractIterativePactTask) {
			AbstractIterativePactTask<?, ?> iterativeTaskContext = (AbstractIterativePactTask<?, ?>) taskContext;
			String identifier = iterativeTaskContext.brokerKey();
			this.hashTable = (CompactingHashTable<IT1>) SolutionSetBroker.instance().get(identifier);
		} else {
			throw new RuntimeException("The task context of this driver is no iterative task context.");
		}
		
		TypeSerializer<IT1> buildSideSerializer = hashTable.getBuildSideSerializer();
		TypeComparator<IT1> buildSideComparator = hashTable.getBuildSideComparator().duplicate();
		
		probeSideSerializer = taskContext.<IT2>getInputSerializer(0).getSerializer();
		probeSideComparator = taskContext.getInputComparator(0);
		
		solutionSideRecord = buildSideSerializer.createInstance();
		
		TypePairComparatorFactory<IT1, IT2> pairCompFactory = taskContext.getTaskConfig().getPairComparatorFactory(taskContext.getUserCodeClassLoader());
		pairComparator = pairCompFactory.createComparator21(buildSideComparator, probeSideComparator);
	}
698566
private void populateTasks(JobDetails job) throws IOException {
    // TODO: see if we can merge common logic here with
    // populateTasks(List<Flow>)
    Table taskTable = hbaseConnection
        .getTable(TableName.valueOf(Constants.HISTORY_TASK_TABLE));
    Scan scan = getTaskScan(job.getJobKey());
    ResultScanner scanner = taskTable.getScanner(scan);
    try {
      // advance through the scanner til we pass keys matching the job
      for (Result currentResult : scanner) {
        if (currentResult == null || currentResult.isEmpty()) {
          break;
        }

        TaskKey taskKey = taskKeyConv.fromBytes(currentResult.getRow());
        TaskDetails task = new TaskDetails(taskKey);
        task.populate(currentResult.getFamilyMap(Constants.INFO_FAM_BYTES));
        job.addTask(task);
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Added " + job.getTasks().size() + " tasks to job "
            + job.getJobKey().toString());
      }
    } finally {
      scanner.close();
      taskTable.close();
    }
  }
1154935
@Override
	public void open(int taskNumber, int numTasks) throws IOException {
		try {
			establishConnection();
			upload = dbConn.prepareStatement(query);
		} catch (SQLException sqe) {
			throw new IllegalArgumentException("open() failed:\t!", sqe);
		} catch (ClassNotFoundException cnfe) {
			throw new IllegalArgumentException("JDBC-Class not found:\t", cnfe);
		}
	}
711818
@Override
	public void onStart() throws Exception {
		try {
			startTaskExecutorServices();
		} catch (Exception e) {
			final TaskManagerException exception = new TaskManagerException(String.format("Could not start the TaskExecutor %s", getAddress()), e);
			onFatalError(exception);
			throw exception;
		}

		startRegistrationTimeout();
	}
189104
void launchTaskJVM(TaskController.TaskControllerContext context) 
                                      throws IOException {
    JvmEnv env = context.env;
    List<String> wrappedCommand = 
      TaskLog.captureOutAndError(env.setup, env.vargs, env.stdout, env.stderr,
          env.logSize, true);
    ShellCommandExecutor shexec = 
        new ShellCommandExecutor(wrappedCommand.toArray(new String[0]), 
                                  env.workDir, env.env);
    // set the ShellCommandExecutor for later use.
    context.shExec = shexec;
    shexec.execute();
  }
1359161
@Override
	public void open(int taskNumber, int numTasks) throws IOException {
		super.open(taskNumber, numTasks);
		
		try {
			this.charset = Charset.forName(charsetName);
		}
		catch (IllegalCharsetNameException e) {
			throw new IOException("The charset " + charsetName + " is not valid.", e);
		}
		catch (UnsupportedCharsetException e) {
			throw new IOException("The charset " + charsetName + " is not supported.", e);
		}
	}
1136546
private void processTasks() throws IOException
   {
      TaskReader reader = new TaskReader(m_data.getTableData("Tasks"));
      reader.read();
      for (MapRow row : reader.getRows())
      {
         processTask(m_project, row);
      }
      updateDates();
   }
125343
public static BatchSession newBatchSessionByThreadSize(KnowledgePackage knowledgePackage,int threadSize){
		return new BatchSessionImpl(knowledgePackage,threadSize,BatchSession.DEFAULT_BATCH_SIZE);
	}
121044
@Override
  void launchTaskJVM(TaskController.TaskControllerContext context) 
                                        throws IOException {
    JvmEnv env = context.env;
    // get the JVM command line.
    String cmdLine = 
      TaskLog.buildCommandLine(env.setup, env.vargs, env.stdout, env.stderr,
          env.logSize, true);

    StringBuffer sb = new StringBuffer();
    //export out all the environment variable before child command as
    //the setuid/setgid binaries would not be getting, any environmental
    //variables which begin with LD_*.
    for(Entry<String, String> entry : env.env.entrySet()) {
      sb.append("export ");
      sb.append(entry.getKey());
      sb.append("=");
      sb.append(entry.getValue());
      sb.append("\n");
    }
    sb.append(cmdLine);
    // write the command to a file in the
    // task specific cache directory
    writeCommand(sb.toString(), getTaskCacheDirectory(context));
    
    // Call the taskcontroller with the right parameters.
    List<String> launchTaskJVMArgs = buildLaunchTaskArgs(context);
    ShellCommandExecutor shExec =  buildTaskControllerExecutor(
                                    TaskCommands.LAUNCH_TASK_JVM, 
                                    env.conf.getUser(),
                                    launchTaskJVMArgs, env.workDir, env.env);
    context.shExec = shExec;
    try {
      shExec.execute();
    } catch (Exception e) {
      LOG.warn("Exception thrown while launching task JVM : " + 
          StringUtils.stringifyException(e));
      LOG.warn("Exit code from task is : " + shExec.getExitCode());
      LOG.warn("Output from task-contoller is : " + shExec.getOutput());
      throw new IOException(e);
    }
    if(LOG.isDebugEnabled()) {
      LOG.debug("output after executing task jvm = " + shExec.getOutput()); 
    }
  }
892190
@Override
    public List<Task> getTasks(String taskType, String startKey, int count) {
        throw new UnsupportedOperationException("This method is not implemented in CassandraExecutionDAO. Please use ExecutionDAOFacade instead.");
    }