Package mongrel2

Examples of mongrel2.App$ZmqVersion


    scpd.setDescription(MusicMessages.MEI_documentation_app_select);
    descriptors.add(scpd);
  }

  private void createDefaultApp() {
    setMeiNode(new App());
  }
View Full Code Here


            handleScoreChild(contentChildForm, saveAllVariants));
      }
      return contentNode;
    } else if (childForm instanceof AppForm) {
      AppForm contentForm = (AppForm) childForm;
      App contentNode = (App) contentForm.getMeiNode();
      contentNode.getRdgs().clear();
      for (BasicElement contentChildForm : contentForm.getChildren()) {
        contentNode.getRdgs().add(
            (Rdg) handleScoreChild(contentChildForm,
                saveAllVariants));
      }
      if (contentNode.isSetRdgs() && contentNode.getRdgs().isEmpty())
        contentNode.unsetRdgs();
      if (contentNode.isSetN() && contentNode.getN().isEmpty())
        contentNode.setN(null);
      if (!saveAllVariants) {
        for (BasicElement contentChildForm : contentForm.getChildren()) {
          if(contentChildForm instanceof ReadingForm && ((ReadingForm)contentChildForm).isActive() ) {
            MeiNode parentMeiNode = contentForm.getParent().getMeiNode();
            for(BasicElement grandChild : ((ReadingForm)contentChildForm).getChildren()){
              MeiNodeNavigator.addMeiNodeAsChild(parentMeiNode, grandChild.getMeiNode());
            }           
          }
        }
        return null;

      }
      return contentNode;
    } else if (childForm instanceof ReadingForm) {
      Rdg contentNode;
      ReadingForm contentForm = (ReadingForm) childForm;
      if (!saveAllVariants && !contentForm.isActive()) {
        // ignore this very reading
        return null;
      }
      contentNode = (Rdg) contentForm.getMeiNode();
      contentNode.getSources().clear();
      for (SourceBindingWrapper sbw : contentForm
          .getSourceBindingWrappers()) { // insert the wrapped sources
        contentNode.getSources().add(sbw.getSource().getId());
      }
      if (contentNode.getSources().isEmpty())
        contentNode.unsetSources();
      contentNode.getMRestsAndKeySigsAndProports().clear();
      for (BasicElement contentChildForm : contentForm.getChildren()) {
        contentNode.getMRestsAndKeySigsAndProports().add(
            handleScoreChild(contentChildForm, saveAllVariants));
      }
      return contentNode;
    } else if (childForm instanceof LayerForm) {
      LayerForm contentForm = (LayerForm) childForm;
      Layer contentNode = (Layer) contentForm.getMeiNode();
      contentNode.getBarLinesAndSyllablesAndGaps().clear();
      for (BasicElement contentChildForm : contentForm.getChildren()) {
        contentNode.getBarLinesAndSyllablesAndGaps().add(
            handleScoreChild(contentChildForm, saveAllVariants));
      }
      return contentNode;
    } else if (childForm instanceof ChordGroupForm) {
      ChordGroupForm contentForm = (ChordGroupForm) childForm;
      Chord contentNode = (Chord) contentForm.getMeiNode();
      contentNode.getRestoresAndArticsAndUnclears().clear();
      for (BasicElement contentChildForm : contentForm.getChildren()) {
        contentNode.getRestoresAndArticsAndUnclears().add(
            handleScoreChild(contentChildForm, saveAllVariants));
      }
      if(contentNode.getArtics().isEmpty()) {
        contentNode.unsetArtics();
      }
      return contentNode;
    } else if (childForm instanceof BeamGroupForm) {
      BeamGroupForm contentForm = (BeamGroupForm) childForm;
      Beam contentNode = (Beam) contentForm.getMeiNode();
      contentNode.getFTremsAndChordsAndDamages().clear();
      for (BasicElement contentChildForm : contentForm.getChildren()) {
        contentNode.getFTremsAndChordsAndDamages().add(
            handleScoreChild(contentChildForm, saveAllVariants));
      }
      return contentNode;
    } else if (childForm instanceof NoteForm) {
      NoteForm contentForm = (NoteForm) childForm;
      Note contentNode = (Note) contentForm.getMeiNode();
      if (contentNode.getArtics().isEmpty())
        contentNode.unsetArtics();
      return contentNode;
    } else if (childForm instanceof RestForm) {
      RestForm contentForm = (RestForm) childForm;
      Rest contentNode = (Rest) contentForm.getMeiNode();
      return contentNode;
    } else if (childForm instanceof MRestForm) {
      MRestForm contentForm = (MRestForm) childForm;
      MRest contentNode = (MRest) contentForm.getMeiNode();
      return contentNode;
    } else if (childForm instanceof SpaceForm) {
      SpaceForm contentForm = (SpaceForm) childForm;
      Space contentNode = (Space) contentForm.getMeiNode();
      return contentNode;
    } else if (childForm instanceof DynamForm) {
      DynamForm contentForm = (DynamForm) childForm;
      Dynam contentNode = (Dynam) contentForm.getMeiNode();
      for (BasicElement contentChildForm : contentForm.getChildren()) {
        contentNode.getContent().add(
            handleScoreChild(contentChildForm, saveAllVariants));
      }
      return contentNode;
    } else if (childForm instanceof TieForm) {
      TieForm contentForm = (TieForm) childForm;
View Full Code Here

    while (this.handler.isActive()) {

      try {

        final HttpRequest req = new HttpRequest();
        this.handler.takeRequest(req);

        final long now = System.currentTimeMillis();
        System.out.printf("%tH:%tM:%tS - %s %s%n", now, now, now, this.senderId, req.getRequestURL());

        final HttpResponse rsp = new HttpResponse();
        rsp.setContent("Hello, world!\n");
        rsp.setStatus(HttpStatus.OK);
        // rsp.setStatus(HttpStatus.BadRequest.code, "Nice Try");
View Full Code Here

      @Override
      public void run() {

        while (handler.isActive()) {
          try {
            final HttpRequest req = new HttpRequest();
            final HttpResponse rsp = new HttpResponse();
            handler.takeRequest(req);
            rsp.setContent("Hello, world!\n");
            rsp.setStatus(HttpStatus.OK);
            handler.sendResponse(rsp, req);
View Full Code Here

        this.handler.takeRequest(req);

        final long now = System.currentTimeMillis();
        System.out.printf("%tH:%tM:%tS - %s %s%n", now, now, now, this.senderId, req.getRequestURL());

        final HttpResponse rsp = new HttpResponse();
        rsp.setContent("Hello, world!\n");
        rsp.setStatus(HttpStatus.OK);
        // rsp.setStatus(HttpStatus.BadRequest.code, "Nice Try");
        rsp.setHeader("Cache-Control", "public");
        rsp.setHeader("X-Handler-App", "TestApp");
        rsp.setHeader("X-Sender-Id", this.senderId);
        rsp.setDateHeader("Last-Updated", System.currentTimeMillis());

        this.handler.sendResponse(rsp, req);

      } catch (final IOException x) {
        x.printStackTrace();
View Full Code Here

      public void run() {

        while (handler.isActive()) {
          try {
            final HttpRequest req = new HttpRequest();
            final HttpResponse rsp = new HttpResponse();
            handler.takeRequest(req);
            rsp.setContent("Hello, world!\n");
            rsp.setStatus(HttpStatus.OK);
            handler.sendResponse(rsp, req);
          } catch (final IOException x) {
            Assert.fail(x.toString());
          }
        } // while
View Full Code Here

  public void testXmlHandler() throws Exception {

    final byte[] contents = "<myxml><msg>hello xml</msg></myxml>".getBytes();

    final Mongrel2Handler handler = new Mongrel2Handler(UUID.randomUUID().toString(), XML_RECV, XML_SEND);
    // handler.setLevel(Level.DEBUG);
    handler.setActive(true);

    final Socket s = new Socket(SERVER_ADDR.getAddress(), SERVER_ADDR.getPort());
    final InputStream in = s.getInputStream();
    final OutputStream out = s.getOutputStream();

    // send message
    // out.write("<myxml>".getBytes());
    out.write(contents);
    out.write(0);
    out.flush();

    // wait to receive message at handler
    final Request req = new Request();
    handler.takeRequest(req);

    // verify correctness
    Assert.assertEquals("server content length unequal", contents.length, req.getContent().length);
    Assert.assertTrue("server contents do not match", Arrays.equals(contents, req.getContent()));

    // echo message back to client
    final Response rsp = new Response();
    rsp.setPayload(contents);
    Assert.assertTrue(Arrays.equals(contents, rsp.getPayload()));
    handler.sendResponse(rsp, req);
    // handler.sendResponse(rsp, req);

    // read out message at client
    final byte[] msg1 = readInputStream(in, true);
    Assert.assertTrue("zero-length message", msg1.length > 0);
View Full Code Here

  private final String senderId;

  public TestApp(final String senderId) {
    this.senderId = senderId;
    this.handler = new Mongrel2Handler(this.senderId, RECV_ADDR, SEND_ADDR);
  }
View Full Code Here

  public void testHttpHandler() throws Exception {

    final ExecutorService executor = Executors.newCachedThreadPool();

    final Mongrel2Handler handler = new Mongrel2Handler(UUID.randomUUID().toString(), HTTP_RECV, HTTP_SEND);
    // handler.setLevel(Level.DEBUG);
    handler.setActive(true);

    final Runnable app = new Runnable() {
      @Override
      public void run() {

        while (handler.isActive()) {
          try {
            final HttpRequest req = new HttpRequest();
            final HttpResponse rsp = new HttpResponse();
            handler.takeRequest(req);
            rsp.setContent("Hello, world!\n");
            rsp.setStatus(HttpStatus.OK);
            handler.sendResponse(rsp, req);
          } catch (final IOException x) {
            Assert.fail(x.toString());
          }
        } // while
View Full Code Here

  public void testJsonHandler() throws Exception {

    final byte[] contents = "{'msg': 'greetings mychat'}".getBytes();

    final Mongrel2Handler handler = new Mongrel2Handler(UUID.randomUUID().toString(), JSON_RECV, JSON_SEND);
    // handler.setLevel(Level.DEBUG);
    handler.setActive(true);

    final Socket s = new Socket(SERVER_ADDR.getAddress(), SERVER_ADDR.getPort());
    final InputStream in = s.getInputStream();
    final OutputStream out = s.getOutputStream();

    // send message
    out.write("@mychat ".getBytes());
    out.write(contents);
    out.write(0);
    out.flush();

    // wait to receive message at handler
    final Request req = new Request();
    handler.takeRequest(req);

    // verify correctness
    Assert.assertEquals("server content length unequal", contents.length, req.getContent().length);
    Assert.assertTrue("server contents do not match", Arrays.equals(contents, req.getContent()));

    // echo message back to client
    final Response rsp = new Response();
    rsp.setPayload(contents);
    Assert.assertTrue(Arrays.equals(contents, rsp.getPayload()));
    handler.sendResponse(rsp, req);

    // read out message at client
    final byte[] msg1 = readInputStream(in, true);
    Assert.assertTrue("zero-length message", msg1.length > 0);
    // decode base64 message
View Full Code Here

TOP

Related Classes of mongrel2.App$ZmqVersion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.