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.bpmscript.jbi.component;
18:
19: import java.util.ArrayList;
20: import java.util.List;
21: import java.util.Map;
22: import java.util.concurrent.ConcurrentHashMap;
23:
24: import javax.jbi.messaging.MessageExchange;
25:
26: import org.bpmscript.BpmScriptException;
27:
28: public class InMemoryExchangeStore implements IExchangeStore {
29:
30: private Map<String, IExchange> exchanges = new ConcurrentHashMap<String, IExchange>();
31:
32: public List<IExchange> findAllExchanges() throws BpmScriptException {
33: return new ArrayList<IExchange>(exchanges.values());
34: }
35:
36: public boolean remove(String exchangeId, IExchangeCallback callback)
37: throws BpmScriptException {
38: IExchange exchange = exchanges.get(exchangeId);
39: if (exchange != null) {
40: try {
41: callback.execute(exchange);
42: exchanges.remove(exchangeId);
43: return true;
44: } catch (Exception e) {
45: return false;
46: }
47: } else {
48: return false;
49: }
50: }
51:
52: public void save(final MessageExchange exchange)
53: throws BpmScriptException {
54: exchanges.put(exchange.getExchangeId(), new IExchange() {
55: public String getExchangeId() {
56: return exchange.getExchangeId();
57: }
58:
59: public MessageExchange getExchange() {
60: return exchange;
61: }
62:
63: });
64: }
65:
66: }
|