public RouteTable unmarshall(StaxUnmarshallerContext context) throws Exception { RouteTable routeTable = new RouteTable(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return routeTable; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("routeTableId", targetDepth)) { routeTable.setRouteTableId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("vpcId", targetDepth)) { routeTable.setVpcId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("routeSet/item", targetDepth)) { routeTable.getRoutes().add(RouteStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("associationSet/item", targetDepth)) { routeTable .getAssociations() .add(RouteTableAssociationStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("tagSet/item", targetDepth)) { routeTable.getTags().add(TagStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("propagatingVgwSet/item", targetDepth)) { routeTable .getPropagatingVgws() .add(PropagatingVgwStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("propagatedRouteSet/item", targetDepth)) { routeTable .getPropagatedRoutes() .add(PropagatedRouteStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return routeTable; } } } }
@Override public void initialize(DTNConfiguration dtn_config) { Iterator<RoutesSetting.RouteEntry> itr = dtn_config.routes_setting().route_entries().iterator(); while (itr.hasNext()) { RoutesSetting.RouteEntry rentry = itr.next(); EndpointIDPattern pattern = new EndpointIDPattern(rentry.dest()); Link link = ContactManager.getInstance().find_link(rentry.link_id()); route_table_.add_entry(new RouteEntry(pattern, link)); } }
@Override protected void handle_link_deleted(LinkDeletedEvent event) { Link link = event.link(); assert (link != null) : "TableBasedRouter: handle_link_deleted: link is null"; route_table_.del_entries_for_nexthop(link); RerouteTimer t = reroute_timers_.get(link.name()); if (t != null) { Log.d(TAG, String.format("link %s deleted, cancelling reroute timer", link.name())); reroute_timers_.remove(link.name()); t.cancel(); } }