(AIR only)
Pacoteair.net
Classepublic dynamic class ServiceMonitor
HerançaServiceMonitor Inheritance EventDispatcher Inheritance Object
Subclasses SocketMonitor, URLMonitor

Base class for service monitors.

Implementa the framework for montoring network services.

This class is included in the ServiceMonitor.swc file.



Propriedades Públicas
 PropriedadeDefinido por
  available : Boolean
Whether the service is currently considered "available." The initial value is false until either a status check sets the property to true or the the property is initialized to true explicitly. Typically, this property is set by the checkStatus() implementation in a subclass or specializer, but if the application has independent information about a service's availability (for exemplo, a request just succeeded or failed), the property can be set explicitly.
ServiceMonitor
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  lastStatusUpdate : Date
[read-only] The time of the last status update.
ServiceMonitor
  pollInterval : Number
The interval, in milliseconds, for polling the server.
ServiceMonitor
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  running : Boolean
[read-only] Whether the monitor has been started.
ServiceMonitor
Métodos Públicos
 MétodoDefinido por
  
Creates a ServiceMonitor object.
ServiceMonitor
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
makeJavascriptSubclass(constructorFunction:Object):void
[static] Adds public ServiceMonitor methods to a JavaScript constructor function's prototype.
ServiceMonitor
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
  
Start the service monitor.
ServiceMonitor
  
Stop monitoring the service.
ServiceMonitor
  
ServiceMonitor
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Métodos Protegidos
 MétodoDefinido por
  
Check the status of the service.
ServiceMonitor
Eventos
 Evento Descrição Definido por
 Inherited Dispatched when Flash Player or the and AIR application gains operating system focus and becomes active.EventDispatcher
 Inherited Dispatched when Flash Player loses operating system focus and is becoming inactive.EventDispatcher
   Indicates that the service status has changed.ServiceMonitor
Detalhes da propriedade
availablepropriedade
available:Boolean  [read-write]

Whether the service is currently considered "available."

The initial value is false until either a status check sets the property to true or the the property is initialized to true explicitly.

Typically, this property is set by the checkStatus() implementation in a subclass or specializer, but if the application has independent information about a service's availability (for exemplo, a request just succeeded or failed), the property can be set explicitly.


Implementação
    public function get available():Boolean
    public function set available(value:Boolean):void
lastStatusUpdatepropriedade 
lastStatusUpdate:Date  [read-only]

The time of the last status update.


Implementação
    public function get lastStatusUpdate():Date
pollIntervalpropriedade 
pollInterval:Number  [read-write]

The interval, in milliseconds, for polling the server.

If zero, the server is not polled periodically, but only immediately after start() is called and when the network status changes.

The default value is 0.


Implementação
    public function get pollInterval():Number
    public function set pollInterval(value:Number):void
runningpropriedade 
running:Boolean  [read-only]

Whether the monitor has been started.


Implementação
    public function get running():Boolean
Detalhes do construtor
ServiceMonitor()Construtor
public function ServiceMonitor()

Creates a ServiceMonitor object.

This class is typically subclassed to monitor specific service types.

After creating a ServiceMonitor object (or a subclass object), call the start() method to begin monitoring the status of the service.

As with the Timer object, the caller should maintain a reference to the ServiceMonitor object. Otherwise, the runtime deletes the object and monitoring ends.

Detalhes do método
checkStatus()método
protected function checkStatus():void

Check the status of the service.

A subclass override method for checking the status of the service.

Typically, this method will initiate a network operation whose completion or failure will result in setting the available property.

JavaScript code can specialise this method by defining a checkStatus() method in the "specializer" object.

makeJavascriptSubclass()método 
public static function makeJavascriptSubclass(constructorFunction:Object):void

Adds public ServiceMonitor methods to a JavaScript constructor function's prototype.

Adds functions to the JavaScript constructor function's prototype that forward public ServiceMonitor functions to the ServiceMonitor. This approximates a normal JavaScript subclass of the ActionScript base class.

A JavaScript class specializing a ServiceMonitor would look like this:

  // JavaScript Constructor function
  function MyHTTPMonitor(url, method)
  {
      // "that" variable makes "this" available in closures below
      var that = this;
      // Required initialization of the service monitor, returns the actual ServiceMonitor object.
      this.monitor = this.initServiceMonitor();
      // Initializes URLStream and event handlers.
      this._urlStream = new air.URLStream();
      this._urlRequest = new air.URLRequest(url);
      if (method)
      {
          this._urlRequest.method = method;
      }
      else
      {
          this._urlRequest.method = "GET";
      }
      function onStatus(event) {
          that.monitor.available = Number(event.status) == 200;
          that._urlStream.close();
      }
      function onError(event)
      {
          that.monitor.available = false;
          that._urlStream.close();
      }
      this._urlStream.addEventListener(air.HTTPStatusEvent.HTTP_RESPONSE_STATUS, onStatus);
      this._urlStream.addEventListener(air.SecurityErrorEvent.SECURITY_ERROR, onError);
      this._urlStream.addEventListener(air.IOErrorEvent.IO_ERROR, onError);
  }
    // Augment JavaScript prototype with public methods from ServiceMonitor
  air.ServiceMonitor.makeJavascriptSubclass(MyHTTPMonitor);
    // Implement specializer functions, just as you would when subclassing a JavaScript class
  MyHTTPMonitor.prototype.checkStatus = function()
  {
      air.trace('OVERRIDDEN checkStatus!', this);
      this._urlStream.load(this._urlRequest);
  }
  

To use the JavaScript class:

  var httpMon = new MyHTTPMonitor('http://www.adobe.com')
  

Be sure to load the AIRAliases.js and ServiceMonitor.swf files with script tags.

Parâmetros

constructorFunction:Object — The JavaScript object's prototype property. For exemplo, if the JavaScript object that you are using to serve as a specializer object is named MyHTTPMonitor, pass MyHTTPMonitor.prototype as the value for this parameter.

start()método 
public function start():void

Start the service monitor.

stop()método 
public function stop():void

Stop monitoring the service.

toString()método 
public override function toString():String

Retorna
String
Detalhes do evento
status Evento
Event Object Type: flash.events.StatusEvent
StatusEvent.type property = flash.events.Event.STATUS

Indicates that the service status has changed.

The value of the "code" property will be either "Service.available" or "Service.unavailable", but best practice is to check the value of the ServiceMonitor.available property.