5 Replies Latest reply on Mar 24, 2010 12:40 AM by saisri2k2

    Blazeds works fine but have to refresh the client to get it to work

    saisri2k2 Level 4

      Blazeds works fine but have to refresh the client to get it to work. when i refresh the blazeds works properly.

       

      I'm pasting my files here let me know if im doing anything wrong.

       

      Thanks.

       

       

      ----service-config.xml

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <services-config>
      
          <services>
              <service-include file-path="remoting-config.xml" />
              <service-include file-path="proxy-config.xml" />
              <service-include file-path="messaging-config.xml" />
               <!--
          Application level default channels. Application level default channels are
          necessary when a dynamic destination is being used by a service component
          and no ChannelSet has been defined for the service component. In that case,
          application level default channels will be used to contact the destination.
              -->  
              <default-channels>
                 <channel ref="my-amf"/>
              </default-channels>
      
      </services>
      
      
          <security>
      <!--      <security-constraint id="sample-users">
                  <auth-method>Custom</auth-method>
                  <roles>
                      <role>sampleusers</role>
                  </roles>
              </security-constraint>
      
      <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>        -->
              <!-- Uncomment the correct app server
              <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
              <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>
              <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
              <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>       
              -->
          </security>
      
          <channels>
      
              <channel-definition id="my-streaming-amf" class="mx.messaging.channels.StreamingAMFChannel">
                  <endpoint url="http://localhost:8080/Hygeia/messagebroker/streamingamf" class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
              </channel-definition>
      
              <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
                  <endpoint url="http://localhost:8080/Hygeia/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
                  <properties>
                      <polling-enabled>false</polling-enabled>
                  </properties>
              </channel-definition>
      
      <!--        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">-->
      <!--            <endpoint url="http://localhost:8080/Hygeia/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>-->
      <!--            <properties>-->
      <!--                <add-no-cache-headers>false</add-no-cache-headers>-->
      <!--            </properties>-->
      <!--        </channel-definition>-->
      
              <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
                  <endpoint url="http://localhost:8080/Hygeia/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
                  <properties>
                      <polling-enabled>true</polling-enabled>
                      <polling-interval-seconds>4</polling-interval-seconds>
                  </properties>
              </channel-definition>
      
          </channels>
      
          <logging>
              <!-- You may also use flex.messaging.log.ServletLogTarget -->
              <target class="flex.messaging.log.ConsoleTarget" level="Error">
                  <properties>
                      <prefix>[BlazeDS] </prefix>
                      <includeDate>false</includeDate>
                      <includeTime>false</includeTime>
                      <includeLevel>true</includeLevel>
                      <includeCategory>false</includeCategory>
                  </properties>
                  <filters>
                      <pattern>Endpoint.*</pattern>
                      <pattern>Service.*</pattern>
                      <pattern>Configuration</pattern>
                  </filters>
              </target>
          </logging>
      
          <system>
              <redeploy>
                  <enabled>true</enabled>
                  <watch-interval>20</watch-interval>
                  <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
                  <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
                  <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
                  <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>           
                  <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
              </redeploy>
          </system>
      
      </services-config>
      
      

      ------Feed.java
      package com.blaze;
       
      import java.util.*;
       
      import org.apache.log4j.Logger;
       
      import com.zts.hygeia.server.web.controllers.ScheduleRequestController;
       
      import flex.messaging.MessageBroker;
      import flex.messaging.messages.AsyncMessage;
      import flex.messaging.util.UUIDUtils;
       
      public class Feed {
      private static FeedThread thread;
      protected final static Logger logger = Logger.getLogger(ScheduleRequestController.class.getName());
       
      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;
      }
      try{
      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);
      }catch(Exception e){
      logger.debug("Exception in the async message block");
      e.printStackTrace();
      }
      try {
      Thread.sleep(300);
      } catch (InterruptedException e) {
      logger.debug("running");
      }
       
      }
      }
      }
       
      }
      
      
      -----DataPush.mxml
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initDataPush();" >
      <mx:Script>
      <![CDATA[
      import mx.messaging.events.MessageFaultEvent;
      import mx.messaging.events.ChannelFaultEvent;
      import mx.controls.Alert;
      import mx.messaging.events.ChannelEvent;
      import mx.messaging.events.MessageEvent;
      import mx.messaging.Consumer;
       
      import mx.messaging.messages.IMessage;
       
      [Bindable] public var consumer:Consumer = null;
       
      public function initDataPush():void{
      consumer = new Consumer();
      consumer.destination = "feed";
      consumer.addEventListener(MessageEvent.MESSAGE,messageHandler);
      consumer.addEventListener(ChannelEvent.CONNECT,connect);
      consumer.addEventListener(ChannelFaultEvent.FAULT,fault);
      consumer.addEventListener(MessageFaultEvent.FAULT,fault1);
      consumer.subscribe();
      var timer:Timer = new Timer(1000,1);
      timer.addEventListener("timer",timerEvent);
      timer.start();
      }
       
      /**
      * If the consumer has got no handle to the feed then refresh / reload untl it gets
      */
      private function timerEvent(evt:TimerEvent):void{
      if(consumer.subscribed){
       
      }else{
      initDataPush();
      }
      }
       
      private function connect(evt:ChannelEvent):void{
      //Alert.show("connected");
      }
       
      private function fault(evt:ChannelFaultEvent):void{
      //Alert.show("fault");
      }
       
      private function fault1(evt:MessageFaultEvent):void{
      //Alert.show("mess fault");
      }
       
      private function messageHandler(message:MessageEvent):void
      {
      pushedValue.text = ""+ message.message.body;
      }
       
      ]]>
      </mx:Script>
       
      <!--<mx:Consumer id="consumer" destination="feed" message="messageHandler(event.message)"/>-->
       
      <mx:Button label="Subscribe to 'feed' destination" click="consumer.subscribe()" enabled="{!consumer.subscribed}"/>
      <mx:Button label="Unsubscribe from 'feed' destination" click="consumer.unsubscribe()" enabled="{consumer.subscribed}" y="30"/>
       
      <mx:TextInput id="pushedValue" x="0" y="60"/>
      </mx:Canvas>