package flex.samples.product; import java.util.ArrayList; public class ProductService { public List getProducts() { List list = new ArrayList(); list.add(new Product(100, "abc")); return list; } } public class Product implements Serializable { private int productId; private String name; public Product(int productId, String name) {...} public int getProductId() { return productId; } public void setProductId(int productId) { this.productId = productId; public String getName() { return name; } public void setName(String name) { this.name = name; } }
import java.util.*; import flex.messaging.MessageBroker; import flex.messaging.messages.AsyncMessage; import flex.messaging.util.UUIDUtils; public class Feed { private static FeedThread thread; public Feed() { } public void start() { if (thread == null) { thread = new FeedThread(); thread.start(); } } public void stop() { thread.running = false; thread = null; } public static class FeedThread extends Thread { public boolean running = true; public void run() { MessageBroker msgBroker = MessageBroker.getMessageBroker(null); String clientID = UUIDUtils.createUUID(); Random random = new Random(); double initialValue = 35; double currentValue = 35; double maxChange = initialValue * 0.005; while (running) { double change = maxChange - random.nextDouble() * maxChange * 2; double newValue = currentValue + change; if (currentValue < initialValue + initialValue * 0.15 && currentValue > initialValue - initialValue * 0.15) { currentValue = newValue; } else { currentValue -= change; } AsyncMessage msg = new AsyncMessage(); msg.setDestination("feed"); msg.setClientId(clientID); msg.setMessageId(UUIDUtils.createUUID()); msg.setTimestamp(System.currentTimeMillis()); msg.setBody(new Double(currentValue)); msgBroker.routeMessageToService(msg, null); System.out.println("" + currentValue); try { Thread.sleep(300); } catch (InterruptedException e) { } } } } }
WEB-INF/flex/messaging-config.xml
1 2 3 4 5 6 7
<destination id="feed"> <!-- Destination specific channel configuration can be defined if needed <channels> <channel ref="my-streaming-amf"/> </channels> --> </destination>