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 */ 017 package org.apache.camel.component.directvm; 018 019 import org.apache.camel.Consumer; 020 import org.apache.camel.Processor; 021 import org.apache.camel.Producer; 022 import org.apache.camel.component.direct.DirectConsumer; 023 import org.apache.camel.impl.DefaultEndpoint; 024 import org.apache.camel.spi.UriEndpoint; 025 import org.apache.camel.spi.UriParam; 026 027 /** 028 * The direct-vm endpoint. 029 */ 030 @UriEndpoint(scheme = "direct-vm", consumerClass = DirectConsumer.class) 031 public class DirectVmEndpoint extends DefaultEndpoint { 032 033 @UriParam 034 private boolean block; 035 @UriParam 036 private long timeout = 30000L; 037 038 public DirectVmEndpoint(String endpointUri, DirectVmComponent component) { 039 super(endpointUri, component); 040 } 041 042 @Override 043 public DirectVmComponent getComponent() { 044 return (DirectVmComponent) super.getComponent(); 045 } 046 047 @Override 048 public Producer createProducer() throws Exception { 049 if (block) { 050 return new DirectVmBlockingProducer(this); 051 } else { 052 return new DirectVmProducer(this); 053 } 054 } 055 056 @Override 057 public Consumer createConsumer(Processor processor) throws Exception { 058 Consumer answer = new DirectVmConsumer(this, new DirectVmProcessor(processor, this)); 059 configureConsumer(answer); 060 return answer; 061 } 062 063 @Override 064 public boolean isSingleton() { 065 return true; 066 } 067 068 public DirectVmConsumer getConsumer() { 069 return getComponent().getConsumer(this); 070 } 071 072 public boolean isBlock() { 073 return block; 074 } 075 076 public void setBlock(boolean block) { 077 this.block = block; 078 } 079 080 public long getTimeout() { 081 return timeout; 082 } 083 084 public void setTimeout(long timeout) { 085 this.timeout = timeout; 086 } 087 }