All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cognifide.aet.common.ProgressMessageProcessor Maven / Gradle / Ivy

There is a newer version: 3.2.2
Show newest version
/**
 * Automated Exploratory Tests
 *
 * Copyright (C) 2013 Cognifide Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cognifide.aet.common;

import com.cognifide.aet.communication.api.exceptions.AETException;
import com.cognifide.aet.communication.api.messages.ProgressMessage;
import com.jcabi.log.Logger;

import org.apache.commons.lang3.StringUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

class ProgressMessageProcessor implements MessageProcessor {

  private static final String DATE_FORMAT = "HH:mm:ss.SSS";

  private static final ThreadLocal DATE_FORMATTER = new ThreadLocal() {
    @Override
    protected DateFormat initialValue() {
      return new SimpleDateFormat(DATE_FORMAT);
    }
  };

  private final ProgressMessage progressMessage;

  ProgressMessageProcessor(ProgressMessage progressMessage) {
    this.progressMessage = progressMessage;
  }

  @Override
  public void process() throws AETException {
    if (progressMessage != null && StringUtils.isNotEmpty(progressMessage.getData())) {
      Logger.info(this, "[%s]: %s", DATE_FORMATTER.get().format(new Date()), progressMessage.getData());
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy