org.apache.camel.example.management.StockService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camel-example-management Show documentation
Show all versions of camel-example-management Show documentation
An example for showing Camel JMX management
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.example.management;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.camel.language.XPath;
/**
* @version
*/
public class StockService {
private final List symbols = new ArrayList();
private Map stat = new ConcurrentHashMap();
public StockService() {
symbols.add("IBM");
symbols.add("APPLE");
symbols.add("ORCL");
}
public String transform(@XPath("/stock/symbol/text()") String symbol, @XPath("/stock/value/text()") String value) {
Integer hits = stat.get(symbol);
if (hits == null) {
hits = 1;
} else {
hits++;
}
stat.put(symbol, hits);
return symbol + "@" + hits;
}
public String getHits() {
return stat.toString();
}
public String createRandomStocks() {
Random ran = new Random();
StringBuilder xml = new StringBuilder();
xml.append("");
xml.append("\n");
for (int i = 0; i < 100; i++) {
int winner = ran.nextInt(symbols.size());
String symbol = symbols.get(winner);
int value = ran.nextInt(1000);
xml.append("");
xml.append("").append(symbol).append(" ");
xml.append("").append(value).append(" ");
xml.append(" \n");
}
xml.append(" ");
return xml.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy