congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
CommandPortService
Code IndexAdd Tabnine to your IDE (free)

How to use
CommandPortService
in
co.cask.cdap.common.service

Best Java code snippets using co.cask.cdap.common.service.CommandPortService (Showing top 9 results out of 315)

origin: caskdata/cdap

/**
 * Returns the port that the server is binded to.
 *
 * @return An int represent the port number.
 */
public int getPort() {
 Preconditions.checkState(isRunning());
 return port;
}
origin: caskdata/cdap

@Override
protected void run() throws Exception {
 LOG.info("Running commandPortService at localhost:" + port);
 serve();
}
origin: cdapio/cdap

@Test
public void testCommandPortServer() throws Exception {
 IncrementCommandHandler handler = new IncrementCommandHandler();
 final CommandPortService server = CommandPortService.builder("test")
                        .addCommandHandler("increment", "Increments a counter", handler)
                        .build();
 Futures.addCallback(server.start(), new FutureCallback<Service.State>() {
  @Override
  public void onSuccess(Service.State result) {
   Socket clientSocket = new Socket("localhost", server.getPort());
   try {
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"));
  server.stopAndWait();
 Assert.assertEquals(Service.State.TERMINATED, server.state());
origin: caskdata/cdap

 /**
  * Builds the {@link CommandPortService}.
  *
  * @return A {@link CommandPortService}.
  */
 public CommandPortService build() {
  if (!hasHelp) {
   final String helpString = helpStringBuilder.toString();
   handlerBuilder.put("help", new CommandHandler() {
    @Override
    public void handle(BufferedWriter respondWriter) throws IOException {
     respondWriter.write(helpString);
     respondWriter.newLine();
    }
   });
  }
  return new CommandPortService(port, handlerBuilder.build());
 }
}
origin: co.cask.cdap/cdap-common

 /**
  * Builds the {@link CommandPortService}.
  *
  * @return A {@link CommandPortService}.
  */
 public CommandPortService build() {
  if (!hasHelp) {
   final String helpString = helpStringBuilder.toString();
   handlerBuilder.put("help", new CommandHandler() {
    @Override
    public void handle(BufferedWriter respondWriter) throws IOException {
     respondWriter.write(helpString);
     respondWriter.newLine();
    }
   });
  }
  return new CommandPortService(port, handlerBuilder.build());
 }
}
origin: co.cask.cdap/cdap-common

/**
 * Returns the port that the server is binded to.
 *
 * @return An int represent the port number.
 */
public int getPort() {
 Preconditions.checkState(isRunning());
 return port;
}
origin: co.cask.cdap/cdap-common

@Override
protected void run() throws Exception {
 LOG.info("Running commandPortService at localhost:" + port);
 serve();
}
origin: caskdata/cdap

while (isRunning()) {
 try {
  Socket socket = serverSocket.accept();
origin: co.cask.cdap/cdap-common

while (isRunning()) {
 try {
  Socket socket = serverSocket.accept();
co.cask.cdap.common.serviceCommandPortService

Javadoc

This class acts as a simple TCP server that accepts textual command and produce textual response. The serving loop is single thread and can only serve one client at a time. CommandHandlers binded to commands are invoked from the serving thread and is expected to return promptly to not blocking the serving thread. Sample usage:
 
CommandPortService service = CommandPortService.builder("myservice") 
.addCommandHandler("ruok", "Are you okay?", ruokHandler) 
.build(); 
service.startAndWait(); 
To stop the service, invoke #stop() or #stopAndWait().

Most used methods

  • <init>
  • builder
    Returns a Builder to build instance of this class.
  • getPort
    Returns the port that the server is binded to.
  • isRunning
  • serve
    Starts accepting incoming request. This method would block until this service is stopped.
  • start
  • state
  • stopAndWait

Popular in Java

  • Making http post requests using okhttp
  • setScale (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • scheduleAtFixedRate (Timer)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Top 17 Plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now