private void sendError(String message, HttpServletResponse res) {
    try {

      HtXmlEventExchangePacket.Packet packet = new HtXmlEventExchangePacket.Packet();
      HtXmlEventExchangePacket.serializeAsErrorMessage(message, packet);
      final ServletOutputStream ostrm = res.getOutputStream();

      HtXmlEventExchangePacket.writePacketToStream(packet, ostrm, ll_m);

    } catch (Throwable e) {
      HtLog.log(
          Level.WARNING,
          getContext(),
          "sendError",
          "Exception in sending error: \"" + e.getMessage() + "\"");
    }
  }
  private void sendFinishReadHistoryFlag(HttpServletResponse res, final ServletOutputStream ostrm)
      throws Exception {

    HtXmlEventExchangePacket.Packet packet =
        new HtXmlEventExchangePacket.Packet(HtXmlEventExchangePacket.PACKET_FINISH_HISTORY);

    HtXmlEventExchangePacket.writePacketToStream(packet, ostrm, ll_m);
  }
  private void sendHeartBeat(HttpServletResponse res, final ServletOutputStream ostrm)
      throws Exception {

    HtXmlEventExchangePacket.Packet packet =
        new HtXmlEventExchangePacket.Packet(HtXmlEventExchangePacket.PACKET_HEARTBEAT);
    HtXmlEventExchangePacket.writePacketToStream(packet, ostrm, ll_m);

    // XmlEvent.createSimpleLog("", this.getContext()+" - " + Thread.currentThread().getId(),
    // CommonLog.LL_DEBUGDETAIL, "Heartbeat arrived");

  }
  // ---------------------------
  // helpers
  private void sendSingleEvent(
      HttpServletResponse res, XmlEvent event, final ServletOutputStream ostrm) throws Exception {

    // need to filter out
    int evnetType = event.getEventType();
    if (evnetType == XmlEvent.ET_CommonLog) {
      CommonLogParameters clp =
          (CommonLogParameters) eventFilterParameters_m.get(XmlEvent.ET_CommonLog);

      CommonLog clog = event.getAsLog();

      // filter

      if (clp.end_date_hist > 0 && clog.getLogDate() > clp.end_date_hist) {
        return;
      }

      if (clp.begin_date_hist > 0 && clog.getLogDate() < clp.begin_date_hist) {
        return;
      }

      if (clog.getLogLevel() > clp.level) {
        return;
      }

      if (clp.threadFilter != null && clp.threadFilter.length() > 0) {
        Matcher mtch = clp.p_threadFilter.matcher(String.valueOf(clog.getLogThread()));
        if (!mtch.find()) {
          return;
        }
      }

      //
      if (clp.contextFilter != null && clp.contextFilter.length() > 0) {
        Matcher mtch = clp.p_contextFilter.matcher(String.valueOf(clog.getContext()));
        if (!mtch.find()) {
          return;
        }
      }

      if (clp.contentSmallFilter != null && clp.contentSmallFilter.length() > 0) {
        Matcher mtch = clp.p_contentSmallFilter.matcher(String.valueOf(clog.getContent()));
        if (!mtch.find()) {
          return;
        }
      }

      if (debugstream_m != null) {
        writeDebugEntry("Sending log event: " + clog.toSmallDebugString());
      }

    } else if (evnetType == XmlEvent.ET_DrawableObject) {
      DrawableObjectParameters clp =
          (DrawableObjectParameters) eventFilterParameters_m.get(XmlEvent.ET_DrawableObject);

      HtDrawableObject dobj = event.getAsDrawableObject();

      if (clp.end_date_hist > 0 && dobj.getTime() > clp.end_date_hist) {
        return;
      }

      if (clp.begin_date_hist > 0 && dobj.getTime() < clp.begin_date_hist) {
        return;
      }

      // filter out by type
      if (clp.allowed_type.size() > 0 && !clp.allowed_type.contains(dobj.getType())) {
        return;
      }

      if (clp.allowed_symbols_m != null) {
        if (!clp.allowed_symbols_m.contains(dobj.getSymbol())) {
          return;
        }
      }

      if (dobj.getType() == HtDrawableObject.DO_TEXT) {

        if (clp.shortTextFilter != null && clp.shortTextFilter.length() > 0) {
          Matcher mtch = clp.p_shortTextFilter.matcher(dobj.getAsText().shortText_m.toString());
          if (!mtch.find()) {
            return;
          }
        }

        if (clp.textFilter != null && clp.textFilter.length() > 0) {
          Matcher mtch = clp.p_textFilter.matcher(dobj.getAsText().text_m.toString());
          if (!mtch.find()) {
            return;
          }
        }
      }

    } else if (evnetType == XmlEvent.ET_RtProviderTicker) {
      RtDataParameters clp =
          (RtDataParameters) eventFilterParameters_m.get(XmlEvent.ET_RtProviderTicker);

      if (clp.allowed_symbols_m != null) {
        if (!clp.allowed_symbols_m.contains(event.getAsRtData().getSymbol())) {
          return;
        }
      }
    }

    HtXmlEventExchangePacket.Packet packet = new HtXmlEventExchangePacket.Packet();
    HtXmlEventExchangePacket.serializeSingleEvent(handler_m, event, packet);

    HtXmlEventExchangePacket.writePacketToStream(packet, ostrm, ll_m);
  }