views:

105

answers:

3

I need to design a new API which models networked devices which have a large amount of attributes which vary quite a lot based on the device's type. The attribute set is not totally arbitrary though, it is a big set of known attributes. That said, with new devices come new attributes so the situation is never totally fixed.

The network devices themselves come and go all the time so that's a central part of the API design. Also, it would be preferable to get updates on the attributes/attribute sets via some variant of the Observer pattern.

Note: I'm not talking about network management, although this might sound like that. That said, the APIs on those systems might very well be suitable/worth looking at.

So my question is, do you know any good APIs out there in the Open Source world from which I could learn and derive some inspiration from?

The system will be Java-based so the examples would preferably be from close relative languages, e.g. Java (of course :)), C#, Scala and other similar statically typed languages.

A: 

Not positive that I understand your question completely, but I'll give it a shot.

Are you looking for a way to allow a device to publicize its attributes when it is on a network? If so, there really isn't a good way unless you write code that understands now to interact with the device. After you have something like that, all you need to have is a class which holds attribute data in some type of data structure of your liking. For updating, you will probably need to poll the devices periodically unless they have a way of reporting when their attributes change:

Dictionary<string, Dictionary<string, string>> deviceAttributes = new 
   Dictionary<string, Dictionary<string, string>>();

void AddAttribute(string deviceIdentifier, string attribute, string value)
{
   if(!deviceAttributes.Keys.Contains(deviceIdentifier))
      deviceAttributes.Add(deviceIdentifier, new Dictionary(attribute, value);
   else
      deviceAttributes[deviceIdentifier].Add(attribute, value);
}

If each device has some kind of standard method for retrieving the attributes of interest, you can write code that would accept an array of whatever and add that to the data structure using a for or foreach loop. I can't really say more without more specific knowledge of what you are trying to do.

Boerema
The system is a network of devices which talk multiple ancient protocols. That part is totally nasty, the implementation of those protocols (binary, largely undocumented, differs from device to device etc.) takes years each. What I'm looking for really is a way to improve the abstraction/API that we currently have which should hide that protocol specific detail and represent the devices in a way which is easy to use and doesn't require a huge amount of duplicate/boilerplate code all over the place.
auramo
+1  A: 

I'm not sure what exactly your API is intended to do, but I'm guessing that since the network devices "come and go all the time" and that you wanted to use the observer pattern, you're looking for something that can get updates on the current state of stuff out on the network.

Have you looked at SLP? It's a pub/sub protocol that may do what you want: it lets network devices broadcast their presence and properties out over the network and also listen for other people. It works over TCP and UDP (unicast and multicast).

There's a couple of java implementations around (like jslp for example), but I was never entirely satisfied with them (so I ended up writing my own). As far as C# goes, I couldn't find one easily.

Seth
Thanks, I'll check out the API (although you already mentioned that it's not satisfying :-) ). Yes, what I didn't mention in the question was that the protocols are already there and there is also an API. Protocols cannot be (ever) changed, but we own the API which represents the devices, so that's my focus and that's what I want to significantly improve.
auramo
SLP is more for devices to represent themselves than to really communicate with each other. Here's the RFC if you're intersted in writing your own subset: http://www.rfc-editor.org/rfc/rfc2608.txt
Seth
A: 

I might look at LDAP/ActiveDirectory/ADAM(User Mode Active Directory) . . . TheEruditeTroglodyte

TheEruditeTroglodyte