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.nagios;
018
019 import com.googlecode.jsendnsca.core.INagiosPassiveCheckSender;
020 import com.googlecode.jsendnsca.core.NagiosPassiveCheckSender;
021 import com.googlecode.jsendnsca.core.NonBlockingNagiosPassiveCheckSender;
022 import org.apache.camel.Component;
023 import org.apache.camel.Consumer;
024 import org.apache.camel.Processor;
025 import org.apache.camel.Producer;
026 import org.apache.camel.impl.DefaultEndpoint;
027 import org.apache.camel.util.ObjectHelper;
028
029 /**
030 * @version $Revision: 17494 $
031 */
032 public class NagiosEndpoint extends DefaultEndpoint {
033
034 private INagiosPassiveCheckSender sender;
035 private NagiosConfiguration configuration;
036 private boolean sendSync = true;
037
038 public NagiosEndpoint() {
039 }
040
041 public NagiosEndpoint(String endpointUri, Component component) {
042 super(endpointUri, component);
043 }
044
045 public Producer createProducer() throws Exception {
046 ObjectHelper.notNull(configuration, "configuration");
047 return new NagiosProducer(this, getSender());
048 }
049
050 public Consumer createConsumer(Processor processor) throws Exception {
051 throw new UnsupportedOperationException("Nagios consumer not supported");
052 }
053
054 public boolean isSingleton() {
055 return true;
056 }
057
058 public NagiosConfiguration getConfiguration() {
059 return configuration;
060 }
061
062 public void setConfiguration(NagiosConfiguration configuration) {
063 this.configuration = configuration;
064 }
065
066 public boolean isSendSync() {
067 return sendSync;
068 }
069
070 public void setSendSync(boolean sendSync) {
071 this.sendSync = sendSync;
072 }
073
074 public synchronized INagiosPassiveCheckSender getSender() {
075 if (sender == null) {
076 if (isSendSync()) {
077 sender = new NagiosPassiveCheckSender(getConfiguration().getNagiosSettings());
078 } else {
079 // use a non blocking sender
080 sender = new NonBlockingNagiosPassiveCheckSender(getConfiguration().getNagiosSettings());
081 }
082 }
083 return sender;
084 }
085
086 public void setSender(INagiosPassiveCheckSender sender) {
087 this.sender = sender;
088 }
089 }