Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: New PureMVC AIR Utility - NetworkMonitor  (Read 6637 times)
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« on: August 26, 2008, 01:51:49 »

I had an idea for a simple PureMVC AIR utility that will send out a notification when your application is offline or online. I'm building my first offline-supported AIR PureMVC application so this is something of value to me. I would love to tap into a notification that is clear and simple: ONLINE or OFFLINE. I can simply register a command with this notification and I can do whatever work necessary when either online or offline. This is the main goal of the utility.

The utility has 2 commands and 1 proxy. The NetworkMonitorProxy to put it simply handles a URLMonitor instance. Once you tell it to start you have no other work to do. No need to add an event listener on NativeApplication.nativeApplication either! The NetworkMonitorProxy will listen for a status event on the URLMonitor instance and using its "available" property determines whether to send an ONLINE or OFFLINE notification. Simple.

Before being able to start the monitor you need to simply register this command:

registerCommand(NetworkMonitor.START_MONITOR, StartNetworkMonitorCommand);

To start the monitor send the following notification with a body being a URL to monitor:

sendNotification(NetworkMonitor.START_MONITOR, "www.myservice.com");

You would follow the same procedures for stopping a monitor with the only difference being sending no body to fire off the command. Also as a helper NetworkMonitorProxy sends out to notifications when a monitor has started NetworkMonitor.MONITOR_STARTED and when it has stopped NetworkMonitor.MONITOR_STOPPED.

Basically all you are going to want to do is handle the following notification constants in your mediators or register it to fire off a custom command: NetworkMonitor.ONLINE or NetworkMonitor.OFFLINE depending on what you need. When these notifications are sent the notification body is the NetworkMonitorProxy instance. I did this since I have several properties you might want access too say for logging or other purposes. Those read-only properties include:

  • online
  • startedOn
  • statusChangedOn
  • url

I couldn't think of anymore to add in but if any of you have ideas let me know. I'd like to see what features you guys might need but I figure since this is pretty simple and straightforward much if not nothing at all else would be needed. I plan to share the code but I'm unfamiliar with procedure of getting a utility out as I would need to change the namespace for PureMVC first.


Cliff,

I've talked to you through email about creating PureMVC utilities and what their namespaces should be. I've completed this utility locally and would love to finally be able to offer something back to the PureMVC community. What do I need to do to get this submitted for approval? Just zip up and send you the code? Commit it to an SVN repo you create? Let me know.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 27, 2008, 08:13:23 »

Hi JJ,

I had an idea for a simple PureMVC AIR utility that will send out a notification when your application is offline or online.

It looks like it would be a useful utility. Particularly if you can start multiple NetworkMonitorProxy instances. If not, you'd probably want to build that in. I'd want to monitor all my hosts.

Also it sounds a little strange calling NetworkMonitor.START_MONITOR with no URL to stop it. Kind of like in Windows having to click the Start button to shut down  :P ...  I'm guessing from this that you're only working with one instance of the Proxy.

As for the PureMVC package space, here is a post that explains how to come up with it:
http://forums.puremvc.org/index.php?topic=142.0

Feel free to send me a copy of the code by email when you're ready and I'll have a look at it.

Cheers,
-=Cliff>
Logged
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« Reply #2 on: August 27, 2008, 09:59:47 »

Cliff thanks for the reply! It currently only supports 1 URLMonitor but I don't see why I couldn't have the proxy handle multiple ones. I'll definitely add support for that. I was thinking this would be desirable by some. I'll just assume that if 1 of all your URLs being monitored gives a status then I know you are online. Would you want to know individually about each monitor and whether you are online? Currently, I send an ONLINE or OFFLINE notification depending on the status. Maybe I do the same but for each monitor? Would be strange though I think, not as simple.

Maybe I should change the constants to START_MONITORING and STOP_MONITORING and I would store the URLs in an array and when stopping, you would pass the same URL and it would be removed from the array. Hmm would need to support though a STOP_ALL_MONITORS.

The code is definitely up to snuff. It's got all ASDoc comments in and I used your XMLDatabase and DesktopCitizen as examples to follow. Quite proud of what I got here. It's simple but I think you'll be pleased. Let me send you what I have with a working example and I'll start working on these new features.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: August 27, 2008, 12:34:21 »

I think I misunderstood what you were doing. I was thinking you were building a network monitor like Ipswitch's What's Up; a tool that is used to determine if your remote servers are up or down, not to detect if your AIR client is online or not. Something network managers would be interested in.

Sorry about that.

-=Cliff>
Logged
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« Reply #4 on: August 27, 2008, 09:01:38 »

Cliff please don't apologize! I don't see how this would really be any different. You have an AIR client interacting with a remote service (in my case its only one, hence the creation of this utility) or several and by knowing if the app is online or offline you have no real other choice but checking against a URL or socket. Hence why this uses the URLMonitor. You simply give it a URL and if it pings it and doesn't get a valid request it then marks the app as offline. It could still be enhanced to say something like: your Network 1 available or whatever.

Either way what did you think about what I sent? Now understanding what I'm going for as is, does it do the job? Is it a utility you would be willing to accept for PureMVC? Let me know. I'm more than open for suggestions/enhancements. It currently does all I need it too but since I'm doing this for the first time I don't have much experience. I figured people who have built many more AIR apps will have different needs.

I'm hoping others chime in and let me know their thoughts. I can post the code now if others are interested since I've tested it and for me its complete for what I need. I can do that tomorrow.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: August 28, 2008, 08:40:41 »

I only had time to peek at the zipfile, but it was full of stuff that doesn't need to be there. Hidden SVN directories, Flex Builder files that you don't want, and .DStore/_MACOSX files nobody needs.

Try this to export your project: in Flex Builder right click on the project, and do Team -> Export and select your desktop.
Now you've just got the code itself in a folder. Zip this up and go into your zip utility and remove the .DStore mac files.

Then upload the code and we can have a look.

-=Cliff>
Logged
Pages: [1]
Print