当前位置: 首页>>代码示例>>Java>>正文


Java ChannelException类代码示例

本文整理汇总了Java中org.apache.flume.ChannelException的典型用法代码示例。如果您正苦于以下问题:Java ChannelException类的具体用法?Java ChannelException怎么用?Java ChannelException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelException类属于org.apache.flume包,在下文中一共展示了ChannelException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: put

import org.apache.flume.ChannelException; //导入依赖的package包/类
/**
 * <p>
 * The method to which {@link BasicChannelSemantics} delegates calls
 * to <code>put</code>.
 * </p>
 */
protected void put(Event event) {
  Preconditions.checkState(Thread.currentThread().getId() == initialThreadId,
      "put() called from different thread than getTransaction()!");
  Preconditions.checkState(state.equals(State.OPEN),
      "put() called when transaction is %s!", state);
  Preconditions.checkArgument(event != null,
      "put() called with null event!");

  try {
    doPut(event);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw new ChannelException(e.toString(), e);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:22,代码来源:BasicTransactionSemantics.java

示例2: take

import org.apache.flume.ChannelException; //导入依赖的package包/类
/**
 * <p>
 * A convenience method for multiple-event <code>take</code> transactions.
 * </p>
 * @return a list of at most <code>max</code> events
 * @see #transact(Channel,Callable)
 */
public static List<Event> take(final Channel channel, final int max)
    throws ChannelException {
  return transact(channel, new Callable<List<Event>>() {
      @Override
      public List<Event> call() {
        List<Event> events = new ArrayList<Event>(max);
        while (events.size() < max) {
          Event event = channel.take();
          if (event == null) {
            break;
          }
          events.add(event);
        }
        return events;
      }
    });
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:ChannelUtils.java

示例3: doTake

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Override
protected Event doTake() throws InterruptedException {
  channelCounter.incrementEventTakeAttemptCount();
  if (takeList.remainingCapacity() == 0) {
    throw new ChannelException("Take list for MemoryTransaction, capacity " +
        takeList.size() + " full, consider committing more frequently, " +
        "increasing capacity, or increasing thread count");
  }
  if (!queueStored.tryAcquire(keepAlive, TimeUnit.SECONDS)) {
    return null;
  }
  Event event;
  synchronized (queueLock) {
    event = queue.poll();
  }
  Preconditions.checkNotNull(event, "Queue.poll returned NULL despite semaphore " +
      "signalling existence of entry");
  takeList.put(event);

  int eventByteSize = (int) Math.ceil(estimateEventSize(event) / byteCapacitySlotSize);
  takeByteCounter += eventByteSize;

  return event;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:MemoryChannel.java

示例4: append

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Override
public Status append(ThriftFlumeEvent event) throws TException {
  Event flumeEvent = EventBuilder.withBody(event.getBody(), event.getHeaders());

  sourceCounter.incrementAppendReceivedCount();
  sourceCounter.incrementEventReceivedCount();

  try {
    getChannelProcessor().processEvent(flumeEvent);
  } catch (ChannelException ex) {
    logger.warn("Thrift source " + getName() + " could not append events " +
                "to the channel.", ex);
    return Status.FAILED;
  }
  sourceCounter.incrementAppendAcceptedCount();
  sourceCounter.incrementEventAcceptedCount();
  return Status.OK;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:19,代码来源:ThriftSource.java

示例5: appendBatch

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Override
public Status appendBatch(List<ThriftFlumeEvent> events) throws TException {
  sourceCounter.incrementAppendBatchReceivedCount();
  sourceCounter.addToEventReceivedCount(events.size());

  List<Event> flumeEvents = Lists.newArrayList();
  for (ThriftFlumeEvent event : events) {
    flumeEvents.add(EventBuilder.withBody(event.getBody(), event.getHeaders()));
  }

  try {
    getChannelProcessor().processEventBatch(flumeEvents);
  } catch (ChannelException ex) {
    logger.warn("Thrift source %s could not append events to the channel.", getName());
    return Status.FAILED;
  }

  sourceCounter.incrementAppendBatchAcceptedCount();
  sourceCounter.addToEventAcceptedCount(events.size());
  return Status.OK;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:22,代码来源:ThriftSource.java

示例6: testExceptionFromGetTransaction

import org.apache.flume.ChannelException; //导入依赖的package包/类
/**
 * Ensure that we bubble up any specific exception thrown from getTransaction
 * instead of another exception masking it such as an NPE
 */
@Test(expected = ChannelException.class)
public void testExceptionFromGetTransaction() {
  // create a channel which unexpectedly throws a ChEx on getTransaction()
  Channel ch = mock(Channel.class);
  when(ch.getTransaction()).thenThrow(new ChannelException("doh!"));

  ChannelSelector sel = new ReplicatingChannelSelector();
  sel.setChannels(Lists.newArrayList(ch));
  ChannelProcessor proc = new ChannelProcessor(sel);

  List<Event> events = Lists.newArrayList();
  events.add(EventBuilder.withBody("event 1", Charsets.UTF_8));

  proc.processEventBatch(events);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:TestChannelProcessor.java

示例7: testTransactionPutCapacityOverload

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Test(expected = ChannelException.class)
public void testTransactionPutCapacityOverload() {
  Context context = new Context();
  Map<String, String> parms = new HashMap<String, String>();
  parms.put("capacity", "5");
  parms.put("transactionCapacity", "2");
  context.putAll(parms);
  Configurables.configure(channel,  context);

  Transaction transaction = channel.getTransaction();
  transaction.begin();
  channel.put(EventBuilder.withBody("test".getBytes()));
  channel.put(EventBuilder.withBody("test".getBytes()));
  // shouldn't be able to fit a third in the buffer
  channel.put(EventBuilder.withBody("test".getBytes()));
  Assert.fail();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:18,代码来源:TestMemoryChannel.java

示例8: testCapacityOverload

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Test(expected = ChannelException.class)
public void testCapacityOverload() {
  Context context = new Context();
  Map<String, String> parms = new HashMap<String, String>();
  parms.put("capacity", "5");
  parms.put("transactionCapacity", "3");
  context.putAll(parms);
  Configurables.configure(channel,  context);

  Transaction transaction = channel.getTransaction();
  transaction.begin();
  channel.put(EventBuilder.withBody("test".getBytes()));
  channel.put(EventBuilder.withBody("test".getBytes()));
  channel.put(EventBuilder.withBody("test".getBytes()));
  transaction.commit();
  transaction.close();

  transaction = channel.getTransaction();
  transaction.begin();
  channel.put(EventBuilder.withBody("test".getBytes()));
  channel.put(EventBuilder.withBody("test".getBytes()));
  channel.put(EventBuilder.withBody("test".getBytes()));
  // this should kill  it
  transaction.commit();
  Assert.fail();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:27,代码来源:TestMemoryChannel.java

示例9: fillChannel

import org.apache.flume.ChannelException; //导入依赖的package包/类
public static Set<String> fillChannel(Channel channel, String prefix) throws Exception {
  Set<String> result = Sets.newHashSet();
  int[] batchSizes = new int[] {
      1000, 100, 10, 1
  };
  for (int i = 0; i < batchSizes.length; i++) {
    try {
      while (true) {
        Set<String> batch = putEvents(channel, prefix, batchSizes[i], Integer.MAX_VALUE, true);
        if (batch.isEmpty()) {
          break;
        }
        result.addAll(batch);
      }
    } catch (ChannelException e) {
      Assert.assertTrue(("The channel has reached it's capacity. This might "
          + "be the result of a sink on the channel having too low of batch "
          + "size, a downstream system running slower than normal, or that "
          + "the channel capacity is just too low. [channel="
          + channel.getName() + "]").equals(e.getMessage())
          || e.getMessage().startsWith("Put queue for FileBackedTransaction of capacity "));
    }
  }
  return result;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:26,代码来源:TestUtils.java

示例10: testEncryptedChannelWithoutEncryptionConfigFails

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Test
public void testEncryptedChannelWithoutEncryptionConfigFails() throws Exception {
  Map<String, String> overrides = getOverridesForEncryption();
  channel = createFileChannel(overrides);
  channel.start();
  Assert.assertTrue(channel.isOpen());
  fillChannel(channel, "will-not-restart");
  channel.stop();
  Map<String, String> noEncryptionOverrides = getOverrides();
  channel = createFileChannel(noEncryptionOverrides);
  channel.start();

  if (channel.isOpen()) {
    try {
      takeEvents(channel, 1, 1);
      Assert.fail("Channel was opened and take did not throw exception");
    } catch (ChannelException ex) {
      // expected
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:22,代码来源:TestFileChannelEncryption.java

示例11: testReconfigure

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Test
public void testReconfigure() throws Exception {
  channel.start();
  Assert.assertTrue(channel.isOpen());
  Set<String> in = Sets.newHashSet();
  try {
    while (true) {
      in.addAll(putEvents(channel, "reconfig", 1, 1));
    }
  } catch (ChannelException e) {
    Assert.assertEquals("The channel has reached it's capacity. "
        + "This might be the result of a sink on the channel having too "
        + "low of batch size, a downstream system running slower than "
        + "normal, or that the channel capacity is just too low. [channel="
        + channel.getName() + "]", e.getMessage());
  }
  Configurables.configure(channel, createContext());
  Set<String> out = takeEvents(channel, 1, Integer.MAX_VALUE);
  compareInputAndOut(in, out);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestFileChannel.java

示例12: commitPutsToPrimary

import org.apache.flume.ChannelException; //导入依赖的package包/类
private void commitPutsToPrimary() {
  synchronized (queueLock) {
    for (Event e : putList) {
      if (!memQueue.offer(e)) {
        throw new ChannelException("Unable to insert event into memory " +
            "queue in spite of spare capacity, this is very unexpected");
      }
    }
    drainOrder.putPrimary(putList.size());
    maxMemQueueSize = (memQueue.size() > maxMemQueueSize) ? memQueue.size()
        : maxMemQueueSize;
    channelCounter.setChannelSize(memQueue.size()
        + drainOrder.overflowCounter);
  }
  // update counters and semaphores
  totalStored.release(putList.size());
  channelCounter.addToEventPutSuccessCount(putList.size());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:19,代码来源:SpillableMemoryChannel.java

示例13: testCapacityDisableOverflow

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Test
public void testCapacityDisableOverflow() {
  Map<String, String> params = new HashMap<String, String>();
  params.put("memoryCapacity", "2");
  params.put("overflowCapacity", "0");   // overflow is disabled effectively
  params.put("overflowTimeout", "0");
  startChannel(params);

  transactionalPutN(0, 2, channel);

  boolean threw = false;
  try {
    transactionalPutN(2, 1, channel);
  } catch (ChannelException e) {
    threw = true;
  }
  Assert.assertTrue("Expecting ChannelFullException to be thrown", threw);

  transactionalTakeN(0, 2, channel);

  Transaction tx = channel.getTransaction();
  tx.begin();
  Assert.assertNull(channel.take());
  tx.commit();
  tx.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:27,代码来源:TestSpillableMemoryChannel.java

示例14: append

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Override
public Void append( AvroFlumeOGEvent evt ) throws AvroRemoteException {
  counterGroup.incrementAndGet("rpc.received");
  Map<String, String> headers = new HashMap<String, String>();

  // extract Flume OG event headers
  headers.put(HOST, evt.getHost().toString());
  headers.put(TIMESTAMP, evt.getTimestamp().toString());
  headers.put(PRIORITY, evt.getPriority().toString());
  headers.put(NANOS, evt.getNanos().toString());
  for (Entry<CharSequence, ByteBuffer> entry : evt.getFields().entrySet()) {
    headers.put(entry.getKey().toString(), entry.getValue().toString());
  }
  headers.put(OG_EVENT, "yes");

  Event event = EventBuilder.withBody(evt.getBody().array(), headers);
  try {
    getChannelProcessor().processEvent(event);
    counterGroup.incrementAndGet("rpc.events");
  } catch (ChannelException ex) {
    return null;
  }

  counterGroup.incrementAndGet("rpc.successful");
  return null;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:27,代码来源:AvroLegacySource.java

示例15: messageReceived

import org.apache.flume.ChannelException; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  LineBasedFrameDecoder.LineEvent line = (LineBasedFrameDecoder.LineEvent) e.getMessage();
  if (line == null) {
    return;
  }
  if (isEvent(line)) {
    try {
      queue.offer(line.getBody());
    } catch (ChannelException ex) {
      logger.error("Error putting event to queue, event dropped", ex);
    }
  } else {
    signalWaiters();
    e.getChannel().write("ok\n");
    if (logger.isDebugEnabled()) {
      logger.debug("Waking up flusher");
    }
  }
}
 
开发者ID:yandex,项目名称:opentsdb-flume,代码行数:21,代码来源:OpenTSDBSource.java


注:本文中的org.apache.flume.ChannelException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。