对具有任意属性的网络设备进行建模的最佳API ?

时间:2021-09-29 22:25:55

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.

我需要设计一个新的API来为网络设备建模,这些设备具有大量的属性,根据设备的类型有很大的不同。属性集不是完全任意的,它是一组已知的属性。也就是说,随着新设备的出现,会出现新的属性,所以情况永远不会完全确定。

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.

网络设备总是来来去去,这是API设计的核心部分。此外,最好通过观察者模式的某些变体获得属性/属性集的更新。

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.

注意:我不是在谈论网络管理,尽管这听起来可能像那样。也就是说,这些系统上的api可能非常适合/值得关注。

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?

所以我的问题是,你知道开源世界里有什么好的api吗?

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.

系统将基于Java,因此示例最好来自密切相关的语言,例如Java(当然是:))、c#、Scala和其他类似的静态类型化语言。

3 个解决方案

#1


1  

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.

我不知道到底你的API是为了做什么,但我猜,自从网络设备“来来去去的”,你想使用观察者模式,你正在寻找的东西能得到更新的当前状态的东西在网络上。

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).

你看过SLP吗?它是一个发布/订阅协议,可以做任何你想做的事情:它允许网络设备通过网络广播它们的存在和属性,也可以监听其他人。它在TCP和UDP(单播和多播)上工作。

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.

有几个java实现(例如jslp),但我从来都不完全满意它们(所以我最终编写了自己的实现)。就c#而言,我找不到一个。

#2


0  

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.

如果每个设备都有某种标准方法来检索所感兴趣的属性,您可以编写代码来接受一个数组,并使用for或foreach循环将其添加到数据结构中。如果我对你要做的事情没有更具体的了解,我真的说不出更多。

#3


0  

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

我可以查看LDAP/ActiveDirectory/ADAM(用户模式活动目录)。TheEruditeTroglodyte

#1


1  

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.

我不知道到底你的API是为了做什么,但我猜,自从网络设备“来来去去的”,你想使用观察者模式,你正在寻找的东西能得到更新的当前状态的东西在网络上。

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).

你看过SLP吗?它是一个发布/订阅协议,可以做任何你想做的事情:它允许网络设备通过网络广播它们的存在和属性,也可以监听其他人。它在TCP和UDP(单播和多播)上工作。

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.

有几个java实现(例如jslp),但我从来都不完全满意它们(所以我最终编写了自己的实现)。就c#而言,我找不到一个。

#2


0  

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.

如果每个设备都有某种标准方法来检索所感兴趣的属性,您可以编写代码来接受一个数组,并使用for或foreach循环将其添加到数据结构中。如果我对你要做的事情没有更具体的了解,我真的说不出更多。

#3


0  

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

我可以查看LDAP/ActiveDirectory/ADAM(用户模式活动目录)。TheEruditeTroglodyte