コード例 #1
0
  @Override
  public void dropStorage() throws MessageQueueException {
    try {
      keyspace.dropColumnFamily(this.queueColumnFamily);
      try {
        Thread.sleep(SCHEMA_CHANGE_DELAY);
      } catch (InterruptedException e) {
      }
    } catch (ConnectionException e) {
      if (!e.getMessage().contains("already exist"))
        throw new MessageQueueException(
            "Failed to create column family for " + queueColumnFamily.getName(), e);
    }

    try {
      keyspace.dropColumnFamily(this.keyIndexColumnFamily);
      try {
        Thread.sleep(SCHEMA_CHANGE_DELAY);
      } catch (InterruptedException e) {
      }
    } catch (ConnectionException e) {
      if (!e.getMessage().contains("already exist"))
        throw new MessageQueueException(
            "Failed to create column family for " + queueColumnFamily.getName(), e);
    }
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  public <R> ExecuteWithFailover<CL, R> newExecuteWithFailover(Operation<CL, R> operation)
      throws ConnectionException {
    try {
      if (operation.getPinnedHost() != null) {
        HostConnectionPool<CL> pool = hosts.get(operation.getPinnedHost());
        if (pool == null) {
          throw new NoAvailableHostsException("Host " + operation.getPinnedHost() + " not active");
        }
        return new RoundRobinExecuteWithFailover<CL, R>(
            config, monitor, Arrays.<HostConnectionPool<CL>>asList(pool), 0);
      }

      int index = roundRobinCounter.incrementAndGet();
      if (index > Integer.MAX_VALUE / 2) {
        roundRobinCounter.set(0);
        index = 0;
      }

      return new RoundRobinExecuteWithFailover<CL, R>(
          config, monitor, topology.getAllPools().getPools(), index);
    } catch (ConnectionException e) {
      monitor.incOperationFailure(e.getHost(), e);
      throw e;
    }
  }
コード例 #3
0
ファイル: CIngestMapper.java プロジェクト: is/demos
 @Override
 public void close() throws IOException {
   if (mb != null && !mb.isEmpty()) {
     try {
       OperationResult<Void> result = mb.execute();
     } catch (ConnectionException e) {
       e.printStackTrace(); // To change body of catch statement use File | Settings | File
       // Templates.
     }
   }
   context.shutdown();
 }
コード例 #4
0
ファイル: CIngestMapper.java プロジェクト: is/demos
  @Override
  public void map(
      LongWritable key,
      Text value,
      OutputCollector<NullWritable, NullWritable> collector,
      Reporter reporter)
      throws IOException {
    if (value.getLength() == 0) return;

    byte[] raw = value.getBytes();

    Map<String, Object> msg = mapper.readValue(raw, Map.class);
    String rowId = createRowId(msg);

    // System.out.println("rowId:" + rowId.toString());
    if (rowId == null) {
      // TODO ... Error Handler
      return;
    }

    if (mb == null) {
      mb = ks.prepareMutationBatch();
    }
    ColumnListMutation<String> c = mb.withRow(cf, rowId);
    c.putColumn("raw", value.toString(), null);

    if (storeAttirbute) {
      for (String k : msg.keySet()) {
        if (k.startsWith("__")) continue;

        Object v = msg.get(k);

        if (v == null) continue;

        if (v.equals("")) continue;

        c.putColumn(k.toLowerCase(), v.toString(), null);
      }
    }

    try {
      if (mb.getRowCount() > 300) {
        OperationResult<Void> result = mb.execute();
        mb = null;
      }
    } catch (ConnectionException e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
      mb = null;
    }
  }