public StreamConsumerImpl() { consumer = new DefaultConsumer(); }
public void consumeLine( String line ) { sb.append( line ); if ( logger != null ) { consumer.consumeLine( line ); } }
channel.basicConsume(queueName, autoAck, "myConsumerTag", new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { //your code here } });
final Waiter waiter = new Waiter(); int consumerCount = 5; // Start consumers for (int i = 0; i < consumerCount; i++) { channel.basicConsume(queueName, true, "myConsumerTag", new DefaultConsumer(channel) { public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(delivery.getBody()); if (message.equals(expectedMessage)) waiter.resume(); } }); } waiter.await(10000, consumerCount);
/** * Execute from the {@code workingDir} * * @param workingDir the directory to execute the javadoc command from * @throws JavadocExecutionException if an exception occurs during the execution of javadoc or if that execution * doesn't exit with {@code 0} */ public void execute(final File dir) throws JavadocExecutionException, IOException { if (!dir.exists()) { Files.createDirectories(dir.toPath()); } cmd.setWorkingDirectory(dir.getAbsolutePath()); int exitCode = 0; try { exitCode = CommandLineUtils.executeCommandLine(cmd, new DefaultConsumer(), new DefaultConsumer()); } catch (Exception ex) { throw new JavadocExecutionException("generateJDiff doclet failed: " + cmd, ex); } if (exitCode != 0) { throw new JavadocExecutionException("generate JDiff doclet " + cmd + " failed with exit code " + exitCode); } }
import com.rabbitmq.client.*; import java.io.IOException; public class Recv { private final static String QUEUE_NAME = "hello"; public static void main(String[] argv) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); System.out.println(" [x] Received '" + message + "'"); } }; channel.basicConsume(QUEUE_NAME, true, consumer); } }
Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope,
private void deleteLocal( StarteamScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version ) throws ScmException { if ( fileSet.getFileList().size() != 0 ) { return; } Commandline cl = createDeleteLocalCommand( repo, fileSet, version ); StreamConsumer consumer = new DefaultConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { throw new ScmException( "Error executing delete-local: " + stderr.toString() ); } }
private void deleteLocal( StarteamScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version ) throws ScmException { if ( fileSet.getFileList().size() != 0 ) { return; } Commandline cl = createDeleteLocalCommand( repo, fileSet, version ); StreamConsumer consumer = new DefaultConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { throw new ScmException( "Error executing delete-local: " + stderr.toString() ); } }
@Component public class SmsQueueConsumer { //I removed the autowiring of the config //@Autowired //Configuration config; //and placed the config as an arg to the constructor public SmsQueueConsumer(Configuration config) throws Exception { //THIS IS WHERE THE NULL POINTER OCCURS (stack trace refers to line 54) String rabbitMqHost = config.getString("rabbitMq.hostName"); ConnectionFactory factory = new ConnectionFactory(); factory.setHost(rabbitMqHost); com.rabbitmq.client.Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(queueName, false, false, false, null); Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { //... handle deliv logic }; } }
protected void executePom(MvnContext context) throws Exception { File tempPom = null; try { StreamConsumer stdout = new DefaultConsumer(); StreamConsumer stderr = new DefaultConsumer(); Commandline cl = getCommandLine(context); showConfig(context, cl); tempPom = prepareFileSystem(context, cl); if (!context.isSilent() && !context.isQuiet()) { log.info(cl.toString()); } int exitValue = CommandLineUtils.executeCommandLine(cl, stdout, stderr); validateExitValue(context, exitValue); } finally { if (context.isDeleteTempPom()) { deleteQuietly(tempPom); } } }
StreamConsumer stderr = new DefaultConsumer();
StreamConsumer stderr = new DefaultConsumer();
@SuppressWarnings("rawtypes") protected Map createEnvs(String commonToolEnvKey, String platform) throws NativeBuildException { File tmpEnvExecFile = null; try { File vsCommonToolDir = this.getCommonToolDirectory(commonToolEnvKey); File vsInstallDir = this.getVisualStudioInstallDirectory(vsCommonToolDir); if (!vsInstallDir.isDirectory()) { throw new NativeBuildException(vsInstallDir.getPath() + " is not a directory."); } tmpEnvExecFile = this.createEnvWrapperFile(vsInstallDir, platform); Commandline cl = new Commandline(); cl.setExecutable(tmpEnvExecFile.getAbsolutePath()); EnvStreamConsumer stdout = new EnvStreamConsumer(); StreamConsumer stderr = new DefaultConsumer(); CommandLineUtils.executeCommandLine(cl, stdout, stderr); return stdout.getParsedEnv(); } catch (Exception e) { throw new NativeBuildException("Unable to retrieve env", e); } finally { if (tmpEnvExecFile != null) { tmpEnvExecFile.delete(); } } }
@SuppressWarnings("rawtypes") protected Map createEnvs(String commonToolEnvKey, String platform) throws NativeBuildException { File tmpEnvExecFile = null; try { File vsCommonToolDir = this.getCommonToolDirectory(commonToolEnvKey); File vsInstallDir = this.getVisualStudioInstallDirectory(vsCommonToolDir); if (!vsInstallDir.isDirectory()) { throw new NativeBuildException(vsInstallDir.getPath() + " is not a directory."); } tmpEnvExecFile = this.createEnvWrapperFile(vsInstallDir, platform); Commandline cl = new Commandline(); cl.setExecutable(tmpEnvExecFile.getAbsolutePath()); EnvStreamConsumer stdout = new EnvStreamConsumer(); StreamConsumer stderr = new DefaultConsumer(); CommandLineUtils.executeCommandLine(cl, stdout, stderr); return stdout.getParsedEnv(); } catch (Exception e) { throw new NativeBuildException("Unable to retrieve env", e); } finally { if (tmpEnvExecFile != null) { tmpEnvExecFile.delete(); } } }
StreamConsumer stderr = new DefaultConsumer();
public static void execute( Commandline cl, Logger logger ) throws NativeBuildException { int ok; try { DefaultConsumer stdout = new DefaultConsumer(); DefaultConsumer stderr = stdout; logger.info( cl.toString() ); ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr ); } catch ( CommandLineException ecx ) { throw new NativeBuildException( "Error executing command line", ecx ); } if ( ok != 0 ) { throw new NativeBuildException( "Error executing command line. Exit code:" + ok ); } } }
StreamConsumer consumer = new DefaultConsumer();
int exitCode = CommandLineUtils.executeCommandLine( cmd, in, new DefaultConsumer(), new DefaultConsumer() );