Messaging中にRemoteObjectにデータを保存したり、メソッド実行したりする際にRemotingObjectにアクセスする方法を忘れないようにメモ。
- パッケージ名:packagename
- Messagingをするクラス名:MessagingAdapter(ServiceAdapterのサブクラス)
- Messagingのadapter-definition id:hoge-messaging-adapter
- RemoteObjectのクラス名:ClassName
- RemoteObjectのdestination id:hoge-remote-object
FlexContext.getServletContext()で取得したServletContextから、getAttribute('destination id')でRemoteObjectの参照を取得する。
これでメッセージングする度にRemoteObjectのsetDataにmessageのbodyが渡されるようになる。
あとは煮るなり焼くなり・・・
- Java
- ClassName.java
- Source
- package packagename;
- import packagename.ClassName;
- import flex.messaging.config.ConfigMap;
- import flex.messaging.messages.Message;
- import flex.messaging.FlexContext;
- import flex.messaging.MessageBroker;
- import flex.messaging.services.MessageService;
- import flex.messaging.services.ServiceAdapter;
- import java.util.HashMap;
- import javax.servlet.ServletContext;
- public class MessagingAdapter extends ServiceAdapter {
- private MessageBroker messageBroker;
- private MessageService messageService;
- private ServletContext servletContext;
- private ClassName remoteObject;
- @Override
- }
- @Override
- public void start() {
- // MessagingService取得
- messageBroker = MessageBroker.getMessageBroker(null);
- messageService = (MessageService) messageBroker.getService("hoge-messaging-service");
- // RemoteObject取得
- servletContext = FlexContext.getServletContext();
- remoteObject = (IconManager) servletContext.getAttribute("hoge-remote-object");
- }
- @Override
- public void stop() {
- }
- @Override
- // Messaging配信
- messageService.pushMessageToClients(message, true);
- messageService.sendPushMessageFromPeer(message, true);
- // RemoteObjectへmessageのbodyを渡す
- remoteObject.setData(hmMessage);
- return null;
- }
- }
ちなみにこの時の*-config.xmlたちはこんな感じ。
- XML
- messaging-config.xml
- Source
- <?xml version="1.0" encoding="UTF-8"?>
- <service id="hoge-messaging-service"
- class="flex.messaging.services.MessageService">
- <adapters>
- <adapter-definition id="actionscript"
- class="flex.messaging.services.messaging.adapters.ActionScriptAdapter"
- default="true" />
- <adapter-definition id="hoge-messaging-service"
- class="packagename.MessagingAdapter" />
- </adapters>
- <!-- ...中略... -->
- </service>
- XML
- remoting-config.xml
- Source
- <?xml version="1.0" encoding="UTF-8"?>
- <service id="hoge-remoting-service" class="flex.messaging.services.RemotingService">
- <!-- ...中略... -->
- <destination id="hoge-remote-object">
- <properties>
- <source>packagename.ClassName</source>
- <scope>application</scope>
- </properties>
- </destination>
- </service>




