• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help on logic for handlers and listners ---  RSS feed

 
avishek bose
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some equipments in a tree strutcure --

.............................................................................................................Element_M
................................................................................................................... |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| .....................................................................................................................|............................................................................................................|
Element1.................................................................................................. Element2 ..........................................................................................Element3


each Element generate some events ... these events have common attributes like Element_name, Element_id, Element_type ... etc...

I can identify the Element uniquely by some naming convension like root/leaf ex- Element_M/Element1

I want to catch the events from each leaf elements and extract some basic attributes from it ....

for that I have a handler and a listner

The listner is configured to listen for the events and is passed to the handler constructor

The problem is the handler is configured for a particular element ex-Element_M/Element1 , to capture all the events from different elements I have to define seperate handlers for seperate elements and then iterate over them to capture the events for a specific element.

Is there a better solution to this as the above process of iteration will take too much of time and resources when we have ,more than 100-200 leaf elements...can we have a single handler on the root elements and able to capture all the events from the childs ....


please suggest

Regards
AK
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
avishek bose wrote:The problem is the handler is configured for a particular element ex-Element_M/Element1 , to capture all the events from different elements I have to define seperate handlers for seperate elements and then iterate over them to capture the events for a specific element.

Why do you have to iterate? Doesn't each element type have an event type associated with it?
 
avishek bose
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Deems wrote:
avishek bose wrote:The problem is the handler is configured for a particular element ex-Element_M/Element1 , to capture all the events from different elements I have to define seperate handlers for seperate elements and then iterate over them to capture the events for a specific element.

Why do you have to iterate? Doesn't each element type have an event type associated with it?



Hi Dennis thanks for the reply ...

yes there is .. let me tell you my logic --

we create the handler for specific elements by providing teh elementid in the constructor
1.ElementHandle el = new ElementHandle(elementid);
add lsitner to the specific handler
2.el.addElementHandleListener(new ElementEventListener());

define the listner
3.ElementEventListener class has method

class ElementEventListener implements ElementListener
{
public void getAttribute(ElementEvent e)
{
if (e.getEventType().equals("eleve"))
{
try
{
HashMap aMap = new HashMap();
aMap.put("Ele_name", e.getEventInfo().get("Element_name"));
aMap.put("ele_id", e.getEventInfo().get("Element_id"));
aMap.put("Ele_type", e.getEventInfo().get("Element_type"));
}catch(Exception e){
}
}
}
}

now as per the above the listner(3) is configured to listen for the event type "eleve" which is same for all elements
This listner is added to the handler(2)

but the handler is configured for a specific element ElementHandle el = new ElementHandle(elementid);
so for every element we have to create seperate handler
ElementHandle el for element1
ElementHandle el2 for element2

and then add them in handler list likewise and process the attributes for all teh events by iterating over the handler ....

is ther any other way to achieve this


regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!