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.saga; 018 019import org.apache.camel.Consumer; 020import org.apache.camel.Processor; 021import org.apache.camel.Producer; 022import org.apache.camel.impl.DefaultEndpoint; 023import org.apache.camel.spi.Metadata; 024import org.apache.camel.spi.UriEndpoint; 025import org.apache.camel.spi.UriPath; 026import org.apache.camel.util.ObjectHelper; 027 028/** 029 * The saga component provides access to advanced options for managing the flow in the Saga EIP. 030 */ 031@UriEndpoint(firstVersion = "2.21.0", scheme = "saga", title = "Saga", syntax = "saga:action", producerOnly = true, label = "core,endpoint") 032public class SagaEndpoint extends DefaultEndpoint { 033 034 public enum SagaEndpointAction { 035 COMPLETE, 036 COMPENSATE 037 } 038 039 @UriPath(description = "Action to execute (complete or compensate)") 040 @Metadata(required = "true") 041 private final SagaEndpointAction action; 042 043 public SagaEndpoint(String endpointUri, SagaComponent component, String action) { 044 super(endpointUri, component); 045 this.action = SagaEndpointAction.valueOf(ObjectHelper.notNull(action, "action").toUpperCase()); 046 } 047 048 @Override 049 public Producer createProducer() throws Exception { 050 if (SagaEndpointAction.COMPLETE.equals(this.action)) { 051 return new SagaProducer(this, true); 052 } else if (SagaEndpointAction.COMPENSATE.equals(this.action)) { 053 return new SagaProducer(this, false); 054 } else { 055 throw new IllegalStateException("Unsupported action '" + this.action + "' in saga endpoint"); 056 } 057 } 058 059 @Override 060 public Consumer createConsumer(Processor processor) throws Exception { 061 throw new UnsupportedOperationException("Consumer not allowed for saga endpoint"); 062 } 063 064 @Override 065 public boolean isSingleton() { 066 return true; 067 } 068 069}