+ Reply to Thread
Results 1 to 10 of 10

Thread: call "interop" for all plugins having desired type

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    call "interop" for all plugins having desired type

    Hello

    I want to send a message (call interop method) from a server plugin to all room server plugins who extends a certain class. For that I think I need to get all instances of desired target plugin, but I don't know how to get this list.

    Example:
    - x rooms use PluginA (room level plugin)
    - I have one server plugin: PluginB
    - I need to do this:
    get all instances of PluginA inside PluginB

    thank you
    serj

  2. #2
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,701
    Thanks
    84
    Thanked 1,178 Times in 1,165 Posts
    The way that I've done this in the past is to have the room plugins call the server plugin during init (or at some later specific point) to tell the server plugin that they exist. The server plugin maintains a data structure with the roomIds and zoneIds of the room plugins. When the server plugin needs to call all the room plugins, it iterates through the data structure, and any time that a plugin isn't found for that roomId/zoneId combo, it drops that element from the data structure (room has been destroyed).

    If you don't want to maintain the data structure, you have to use getZones and then iterate through every zone, and every room in each zone, trying to find the plugin from the room. If you can cast it into the class you expect, then call the interop method on it.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hello Teressa
    Thank you for your answer.

    I want to use your second ideea (to get rooms by iterating each zone), but I don't see how this will work, because RoomValue don't extends BasePlugin.
    Here is my code:
    Code:
    	public void request(long caller, Map map){
    		Collection<ZoneValue> zones = getApi().getZones();
    		for(ZoneValue z:zones){
    			Collection<RoomValue> rooms = getApi().getRoomsInZone(z.getZoneId());
    			for(RoomValue roomValue:rooms){
    				//TODO how to cast here because RoomValue don't extend BasePlugin???
    				//if(roomValue instanceof BasePlugin){//<--- compile error
    				//}
    			}
    		}
    	}

  4. #4
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,701
    Thanks
    84
    Thanked 1,178 Times in 1,165 Posts
    Ah.... if your room plugins are going to be various classes, you will need to have your data structure also hold the String that is the name of the plugin class.

    If the room plugin is in the same extension as the server plugin, the server plugin could then do:
    Code:
    MyRoomPlugin roomPlugin = (MyRoomPlugin) getApi().getRoomPlugin(zoneId, roomId, "MyRoomPlugin");
    If all your room plugins that would need this feature extend an intermediate class that has the method that the server plugin needs to invoke, you could change the MyRoomPlugin above to that intermediate class, keeping the string that identifies the plugin.

    At this point, you can then invoke any public method on the roomPlugin class.

    For room plugins in a different extension, it's almost the same.
    Code:
    EsObject results = getApi().callRoomPlugin(zoneId, roomId, "MyRoomPlugin", parameters);
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  5. #5
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,701
    Thanks
    84
    Thanked 1,178 Times in 1,165 Posts
    Oh that's right, it won't work with the second method. Unless you have just a few possible plugin classes, and you try each of them on each of the rooms. That's far more brute force than I'd want to try.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  6. #6
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    in ElectroServerApi class (what is used by calling getApi() from plugin) there is no method named getRoomPlugin
    So, only one solution for this: to add plugins to a colection and iterate it when need

  7. #7
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,701
    Thanks
    84
    Thanked 1,178 Times in 1,165 Posts
    yes there is. getRoomPlugin

    note that this doesn't tell you the name of the plugin - you have to know that. it gets the instance of the plugin that you specify that is attached to the room.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  8. #8
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I don't have it (see image with all methods), but it's ok. I will use first solution

    thank you
    serj
    Attached Images

  9. #9
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,701
    Thanks
    84
    Thanked 1,178 Times in 1,165 Posts
    What version of ES4 are you running? getRoomPlugin has been in there for years.

    I can help you migrate to the latest version of ES4 if you like. It's easy.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  10. #10
    Former Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,701
    Thanks
    84
    Thanked 1,178 Times in 1,165 Posts
    I see getApi().getRoomPlugin in the server api for ES4.0.4, which is as far back as it's easy for me to check. Either what you are showing is a VERY early version of ES4, or it's ES3.
    Teresa Carrigan
    Senior Software Developer
    Janus Research Group, Inc.
    previously
    Senior Engineer
    Electrotank, Inc.

  11. The Following User Says Thank You to tcarr For This Useful Post:

    serj (09-06-2011)

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts