@Override public void onTerminating() { this.pipe.close(); } }
@Override public void writeMonitoringRecord(final IMonitoringRecord record) { this.pipe.writeMonitoringRecord(record); }
/** * Creates a new instance of this class using the given parameters. * * @param configuration * The configuration for this component. * @param projectContext * The project context for this component. */ public PipeReader(final String pipeName) { this.pipe = Broker.INSTANCE.acquirePipe(pipeName); if (this.pipe == null) { throw new IllegalArgumentException("Failed to get Pipe with name " + pipeName); } else { if (this.logger.isDebugEnabled()) { this.logger.debug("Connected to named pipe '" + this.pipe.getName() + "'"); } } // escaping this in constructor! very bad practice! this.pipe.setPipeReader(this); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(64); sb.append(super.toString()); sb.append("\n\tConnected to pipe: '"); sb.append(this.pipe.getName()); sb.append('\''); return sb.toString(); }
/** * Creates an {@link kieker.common.namedRecordPipe.IPipeReader IPipeReader} that collects records from a * {@link Pipe} and collects these in the returned {@link List}. * * @param pipeName * The name of the pipe to use. * @return a synchronized list which contains the collected records */ public static List<IMonitoringRecord> createAndRegisterNamedPipeRecordCollector(final String pipeName) { final List<IMonitoringRecord> receivedRecords = Collections .synchronizedList(new ArrayList<IMonitoringRecord>()); final Pipe namedPipe = Broker.INSTANCE.acquirePipe(pipeName); namedPipe.setPipeReader(new IPipeReader() { @Override public void notifyPipeClosed() { // do nothing } @Override public boolean newMonitoringRecord(final IMonitoringRecord record) { return receivedRecords.add(record); } }); return receivedRecords; } }
/** * Returns a connection with name {@code pipeName}. If a connection with this * name does not exist prior to the call, it is created. * * @param pipeName * The name of the pipe. * * @return The acquired pipe. * * @throws IllegalArgumentException * If the pipe name is null or empty. */ public Pipe acquirePipe(final String pipeName) throws IllegalArgumentException { Pipe conn; synchronized (this) { if ((pipeName == null) || (pipeName.length() == 0)) { // LOG.error(errorMsg); no need to log if thrown throw new IllegalArgumentException("pipeName must not be null or empty! (Found: " + pipeName + ")"); } final Pipe newPipe = new Pipe(pipeName); conn = this.pipeMap.putIfAbsent(pipeName, newPipe); if (conn == null) { return newPipe; } else { return conn; } } } }
/** * Creates a new instance of this class using the given parameters. * * @param configuration * The configuration for this component. * @param projectContext * The project context for this component. */ public PipeReader(final Configuration configuration, final IProjectContext projectContext) { super(configuration, projectContext); final String pipeNameConfig = this.configuration.getStringProperty(CONFIG_PROPERTY_NAME_PIPENAME); this.pipeName = pipeNameConfig; this.pipe = Broker.INSTANCE.acquirePipe(pipeNameConfig); if (this.pipe == null) { throw new IllegalArgumentException("Failed to get Pipe with name " + pipeNameConfig); } else { this.logger.debug("Connected to named pipe '{}'", this.pipe.getName()); } // escaping this in constructor! very bad practice! this.pipe.setPipeReader(this); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(64); sb.append(super.toString()). append("\n\tConnected to pipe: '").append(this.pipe.getName()). append('\''); return sb.toString(); }
/** * Returns a connection with name {@code pipeName}. If a connection with this * name does not exist prior to the call, it is created. * * @param pipeName * The name of the pipe. * * @return The acquired pipe. * * @throws IllegalArgumentException * If the pipe name is null or empty. */ public Pipe acquirePipe(final String pipeName) throws IllegalArgumentException { synchronized (this) { if ((pipeName == null) || (pipeName.length() == 0)) { // LOG.error(errorMsg); no need to log if thrown throw new IllegalArgumentException("pipeName must not be null or empty! (Found: " + pipeName + ")"); } final Pipe newPipe = new Pipe(pipeName); final Pipe conn = this.pipeMap.putIfAbsent(pipeName, newPipe); if (conn == null) { return newPipe; } else { return conn; } } } }
/** * Creates a new instance of this class using the given parameters. * * @param configuration * The configuration for this component. * @param projectContext * The project context for this component. */ public PipeReader(final Configuration configuration, final IProjectContext projectContext) { super(configuration, projectContext); final String pipeNameConfig = this.configuration.getStringProperty(CONFIG_PROPERTY_NAME_PIPENAME); this.pipeName = pipeNameConfig; this.pipe = Broker.INSTANCE.acquirePipe(pipeNameConfig); if (this.pipe == null) { throw new IllegalArgumentException("Failed to get Pipe with name " + pipeNameConfig); } else { if (this.log.isDebugEnabled()) { this.log.debug("Connected to named pipe '" + this.pipe.getName() + "'"); } } // escaping this in constructor! very bad practice! this.pipe.setPipeReader(this); }
/** * {@inheritDoc} */ @Override public void terminate(final boolean error) { // will lead to notifyPipeClosed() and the subsequent termination of read() if (this.pipe != null) { this.pipe.close(); } }
@Override public void writeMonitoringRecord(final IMonitoringRecord record) { this.pipe.writeMonitoringRecord(record); }
@Override public void onTerminating() { this.pipe.close(); } }
/** * {@inheritDoc} */ @Override public void terminate(final boolean error) { // will lead to notifyPipeClosed() and the subsequent termination of read() if (this.pipe != null) { this.pipe.close(); } }
/** * {@inheritDoc} */ @Override public void terminateStage() { // will lead to notifyPipeClosed() and the subsequent termination of read() if (this.pipe != null) { this.pipe.close(); } super.terminateStage(); }