Exemplo n.º 1
0
  protected EventsCalculationThread(
      Date startDate,
      Date endDate,
      String eventListName,
      Currency calculationCurrency,
      Set<Observer> observers,
      Boolean keepCache,
      Queue eventQueue,
      JmsTemplate jmsTemplate) {

    super();
    this.startDate = startDate;
    this.endDate = endDate;
    this.eventListName = eventListName;
    this.calculationCurrency = calculationCurrency;

    this.keepCache = keepCache;
    this.eventQueue = eventQueue;
    this.jmsTemplate = jmsTemplate;

    this.configs = ConfigThreadLocal.getAll();

    this.observers = observers;
    for (Observer observer : observers) {
      this.addObserver(observer);
    }
  }
Exemplo n.º 2
0
  private void updateBarChart(
      final Stock selectedShare,
      Date exentedStartDate,
      final Boolean recalculationGranted,
      final Boolean needsUpdate) {

    final Map<String, Config> configs = ConfigThreadLocal.getAll();

    Observer barDataObs =
        new Observer() {

          @Override
          public void update(Observable o, final Object arg) {

            final Set<EventInfo> noDataTrends = new HashSet<EventInfo>();

            if (arg == null
                || ((SymbolEvents) arg).getDataResultMap().isEmpty()) { // No events found

              if (!recalculationGranted) { // No events found despite recalc
                chartTarget.getMainChartWraper().resetBarChart();
              } else {
                noDataTrends.addAll(chartTarget.getChartedEvtDefsTrends());
              }

            } else { // That's all or partially good, we display

              final Map<EventInfo, TuningResDTO> tuningRess =
                  new ConcurrentHashMap<EventInfo, TuningResDTO>();
              for (final EventInfo eventDefinition : chartTarget.getChartedEvtDefsTrends()) {

                TuningResDTO tuningResCache = null;
                try {
                  tuningResCache =
                      chartTarget
                          .getHightlitedEventModel()
                          .updateTuningRes(
                              selectedShare,
                              eventDefinition,
                              chartTarget.getSlidingStartDate(),
                              chartTarget.getSlidingEndDate());
                } catch (Exception e) {
                  LOGGER.error(e, e);
                }
                if (tuningResCache != null) {
                  tuningRess.put(eventDefinition, tuningResCache);
                } else {
                  noDataTrends.add(eventDefinition);
                }
              }

              Runnable runnable =
                  new Runnable() {
                    public void run() {
                      try {
                        SymbolEvents ses = (SymbolEvents) arg;
                        SortedMap<DataSetBarDescr, SortedMap<Date, Double>> barsData =
                            ChartBarUtils.buildBarsData(
                                selectedShare,
                                chartTarget.getChartedEvtDefsTrends(),
                                chartTarget.getSlidingStartDate(),
                                chartTarget.getSlidingEndDate(),
                                ses,
                                tuningRess,
                                barChartSettings);
                        chartTarget
                            .getMainChartWraper()
                            .updateBarDataSet(
                                barsData,
                                chartTarget.getHighligtedId(),
                                barChartSettings,
                                chartTarget.getPlotChartDimensions());
                      } catch (Exception e) {
                        LOGGER.error(
                            "arg : "
                                + arg
                                + ", chartTarget.getMainChartWraper() : "
                                + chartTarget.getMainChartWraper()
                                + ", chartTarget.getHighligtedId() : "
                                + chartTarget.getHighligtedId()
                                + ", barChartSettings : "
                                + barChartSettings
                                + ", chartTarget.getPlotChartDimensions() : "
                                + chartTarget.getPlotChartDimensions(),
                            e);
                      }
                    }
                  };
              try {
                EventQueue.invokeAndWait(runnable);
              } catch (Exception e) {
                LOGGER.error(e, e);
              }
            }

            // Missing bars
            if (!needsUpdate && !noDataTrends.isEmpty()) {
              String chartedEvtStr =
                  EventDefinition.getReadableEventDefSetAsString(", ", noDataTrends);
              String errMsg =
                  "No events are available for : "
                      + chartedEvtStr
                      + " and "
                      + selectedShare.getFriendlyName()
                      + " within the period you have selected.\n"
                      + "If you just cleared the calculation results, you may want to Force and Update the calculations.";
              String addMsg =
                  "This may also happen if calculations failed or if there is not enough quotations for the period.\n"
                      +
                      // + "Check the selected Trends in " + TRENDBUTTXT + " as well as the date
                      // boundaries against the available quotations.\n"
                      "You may want to check the date boundaries against the available quotations.\n"
                      + "Also note that some calculators need full OLHC and Volume in order to be calculated.\n"
                      + "If '"
                      + chartedEvtStr
                      + "' is one of your calculators you may also want to check its formula.";
              showPopupDialog(errMsg, "Ok", addMsg, null);
            }
          }
        };

    Observable eventsDataLoader = new EventsDataLoader(configs, selectedShare, exentedStartDate);
    eventsDataLoader.addObserver(barDataObs);

    Thread updateBarChartThread = new Thread((Runnable) eventsDataLoader);
    updateBarChartThread.start();
  }