@Override public synchronized void stop() throws Exception { // stop listening to the transport if (this.transport.isListening()) { this.transport.close(); } super.stop(); }
private int getMaxMessageSize() { int totalMaxMessageSize = 2147483647; for (TransportMapping transportMapping : transportMappings) { int maxMsgSize = (transportMapping).getMaxInboundMessageSize(); totalMaxMessageSize = Math.min(totalMaxMessageSize, maxMsgSize); } return totalMaxMessageSize; }
/** * Builds target resource. * @param context Process context */ private void buildTargetResource(ProcessContext context) { if((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) { try { this.transportMapping = new DefaultUdpTransportMapping(); this.snmp = new Snmp(this.transportMapping); if("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) { USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); } this.transportMapping.listen(); } catch (Exception e) { throw new IllegalStateException("Failed to initialize UDP transport mapping", e); } } if (this.snmpTarget == null) { this.snmpTarget = this.createSnmpTarget(context); } if (this.targetResource == null) { this.targetResource = this.finishBuildingTargetResource(context); } }
((ConnectionOrientedTransportMapping)transportMapping).setConnectionTimeout(0); transportMapping.addTransportListener(messageDispatcher); if (notificationDispatcher == null) { notificationDispatcher = new NotificationDispatcher(); transportMapping.listen(); if (logger.isInfoEnabled()) { logger.info("Added notification listener for address: "+
/** * Will close current SNMP mapping. */ @OnStopped public void close() { try { if (this.targetResource != null) { this.targetResource.close(); } } catch (Exception e) { this.getLogger().warn("Failure while closing target resource " + this.targetResource, e); } this.targetResource = null; try { if (this.transportMapping != null) { this.transportMapping.close(); } } catch (IOException e) { this.getLogger().warn("Failure while closing UDP transport mapping", e); } this.transportMapping = null; try { if (this.snmp != null) { this.snmp.close(); } } catch (IOException e) { this.getLogger().warn("Failure while closing UDP transport mapping", e); } this.snmp = null; }
public synchronized boolean removeNotificationListener(Address listenAddress) { TransportMapping tm = (TransportMapping)notificationListeners.remove(listenAddress); if (tm == null) { return false; } tm.removeTransportListener(messageDispatcher); notificationTransports.remove(tm); try { tm.close(); } catch (IOException ex) { logger.error(ex); if (logger.isDebugEnabled()) { ex.printStackTrace(); } } return true; }
protected void registerTransportMappings() { ArrayList l = new ArrayList(dispatcher.getTransportMappings()); for (Iterator it = l.iterator(); it.hasNext();) { TransportMapping tm = (TransportMapping) it.next(); tm.removeTransportListener(dispatcher); tm.addTransportListener(dispatcher); } }
private static void checkListening4ConfirmedPDU(PDU pdu, Address target, TransportMapping transport) { if ((transport != null) && (!transport.isListening())) { logger.warn("Sending confirmed PDU "+pdu+" to target "+target+ " although transport mapping "+transport+ " is not listening for a response"); } }
/** * Removes the specified transport mapping from this SNMP session. * If the transport mapping is not currently part of this SNMP session, * this method will have no effect. * @param transportMapping * a previously added <code>TransportMapping</code>. */ public void removeTransportMapping(TransportMapping<? extends Address> transportMapping) { messageDispatcher.removeTransportMapping(transportMapping); transportMapping.removeTransportListener(messageDispatcher); }
/** * Adds a <code>TransportMapping</code> to this SNMP session. * @param transportMapping * a <code>TransportMapping</code> instance. */ public void addTransportMapping(TransportMapping<? extends Address> transportMapping) { // connect transport mapping with message dispatcher messageDispatcher.addTransportMapping(transportMapping); transportMapping.addTransportListener(messageDispatcher); }
/** * Puts a list of transport mappings into listen mode. * * @param transportMappings * a list of {@link TransportMapping} instances. * * @throws IOException * if a transport cannot listen to incoming messages. */ protected static void launchTransportMappings(Collection<? extends TransportMapping> transportMappings) throws IOException { ArrayList<? extends TransportMapping> l = new ArrayList<TransportMapping>(transportMappings); for (TransportMapping tm : l) { if (!tm.isListening()) { tm.listen(); } } }
((ConnectionOrientedTransportMapping) transportMapping).setConnectionTimeout(0); transportMapping.addTransportListener(messageDispatcher); if (notificationDispatcher == null) { notificationDispatcher = new NotificationDispatcher(); transportMapping.listen(); if (logger.isInfoEnabled()) { logger.info("Added notification listener for address: " +
/** * Closes a list of transport mappings. * * @param transportMappings * a list of {@link TransportMapping} instances. * * @throws IOException * if a transport cannot be closed. */ protected static void stopTransportMappings(Collection<? extends TransportMapping> transportMappings) throws IOException { ArrayList<TransportMapping> l = new ArrayList<TransportMapping>(transportMappings); for (TransportMapping tm : l) { tm.close(); } }
protected void registerTransportMappings() { ArrayList<TransportMapping> l = new ArrayList<>(dispatcher.getTransportMappings()); for (TransportMapping tm : l) { tm.removeTransportListener(dispatcher); tm.addTransportListener(dispatcher); if (tm instanceof X509TlsTransportMappingConfig) { ((X509TlsTransportMappingConfig) tm).setSecurityCallback(tlsTmMib); } } }
private static void checkListening4ConfirmedPDU(PDU pdu, Address target, TransportMapping<?> transport) { if ((transport != null) && (!transport.isListening())) { logger.warn("Sending confirmed PDU " + pdu + " to target " + target + " although transport mapping " + transport + " is not listening for a response"); } }
public synchronized boolean removeNotificationListener(Address listenAddress) { TransportMapping tm = notificationListeners.remove(listenAddress); if (tm == null) { return false; } tm.removeTransportListener(messageDispatcher); notificationTransports.remove(tm); closeTransportMapping(tm); return true; }
/** * Adds a <code>TransportMapping</code> to this SNMP session. * * @param transportMapping * a <code>TransportMapping</code> instance. */ public void addTransportMapping(TransportMapping<? extends Address> transportMapping) { // connect transport mapping with message dispatcher messageDispatcher.addTransportMapping(transportMapping); transportMapping.addTransportListener(messageDispatcher); }
/** * Start listening for responses * * @throws IOException */ public void startListen() throws IOException { transport.listen(); listening = true; }
/** * Puts all associated transport mappings into listen mode. * @throws IOException * if a transport mapping throws an <code>IOException</code> when its * {@link TransportMapping#listen()} method has been called. */ public void listen() throws IOException { for (TransportMapping tm : messageDispatcher.getTransportMappings()) { if (!tm.isListening()) { tm.listen(); } } }