01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.bean.beans;
18:
19: import java.util.concurrent.ExecutionException;
20: import java.util.concurrent.Future;
21:
22: import javax.annotation.PostConstruct;
23: import javax.annotation.PreDestroy;
24: import javax.annotation.Resource;
25: import javax.jbi.component.ComponentContext;
26: import javax.jbi.messaging.DeliveryChannel;
27: import javax.jbi.messaging.NormalizedMessage;
28:
29: import org.apache.servicemix.bean.Callback;
30: import org.apache.servicemix.bean.Destination;
31: import org.apache.servicemix.bean.ExchangeTarget;
32: import org.apache.servicemix.bean.Operation;
33: import org.apache.servicemix.jbi.util.MessageUtil;
34:
35: public class ConsumerBean {
36:
37: private Future<NormalizedMessage> request1;
38: private Future<NormalizedMessage> request2;
39:
40: @Resource
41: private ComponentContext context;
42:
43: @Resource
44: private DeliveryChannel channel;
45:
46: @ExchangeTarget(uri="service:urn:service1")
47: private Destination service1;
48:
49: @ExchangeTarget(uri="service:urn:service2")
50: private Destination service2;
51:
52: /**
53: * @return the request1
54: */
55: public Future<NormalizedMessage> getRequest1() {
56: return request1;
57: }
58:
59: /**
60: * @return the request2
61: */
62: public Future<NormalizedMessage> getRequest2() {
63: return request2;
64: }
65:
66: @PostConstruct
67: public void init() {
68: if (service1 == null || service2 == null || context == null
69: || channel == null) {
70: throw new IllegalStateException("Bean not initialized");
71: }
72: }
73:
74: @PreDestroy
75: public void destroy() {
76: }
77:
78: @Operation
79: public void receive(NormalizedMessage message) throws Exception {
80: request1 = service1.send(MessageUtil.copy(message));
81: request2 = service2.send(MessageUtil.copy(message));
82: }
83:
84: @Callback(condition="this.request1.done && this.request2.done")
85: public NormalizedMessage answer() throws InterruptedException,
86: ExecutionException {
87: request1.get();
88: request2.get();
89: return null;
90: }
91:
92: }
|