001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.component.direct; 018 019import org.apache.camel.Endpoint; 020import org.apache.camel.Processor; 021import org.apache.camel.ShutdownRunningTask; 022import org.apache.camel.Suspendable; 023import org.apache.camel.impl.DefaultConsumer; 024import org.apache.camel.spi.ShutdownAware; 025 026/** 027 * The direct consumer. 028 * 029 * @version 030 */ 031public class DirectConsumer extends DefaultConsumer implements ShutdownAware, Suspendable { 032 033 private DirectEndpoint endpoint; 034 035 public DirectConsumer(Endpoint endpoint, Processor processor) { 036 super(endpoint, processor); 037 this.endpoint = (DirectEndpoint) endpoint; 038 } 039 040 @Override 041 public DirectEndpoint getEndpoint() { 042 return (DirectEndpoint) super.getEndpoint(); 043 } 044 045 @Override 046 protected void doStart() throws Exception { 047 super.doStart(); 048 endpoint.addConsumer(this); 049 } 050 051 @Override 052 protected void doStop() throws Exception { 053 endpoint.removeConsumer(this); 054 super.doStop(); 055 } 056 057 @Override 058 protected void doSuspend() throws Exception { 059 endpoint.removeConsumer(this); 060 } 061 062 @Override 063 protected void doResume() throws Exception { 064 // resume by using the start logic 065 endpoint.addConsumer(this); 066 } 067 068 public boolean deferShutdown(ShutdownRunningTask shutdownRunningTask) { 069 // deny stopping on shutdown as we want direct consumers to run in case some other queues 070 // depend on this consumer to run, so it can complete its exchanges 071 return true; 072 } 073 074 public int getPendingExchangesSize() { 075 // return 0 as we do not have an internal memory queue with a variable size 076 // of inflight messages. 077 return 0; 078 } 079 080 public void prepareShutdown(boolean suspendOnly, boolean forced) { 081 // noop 082 } 083}