public void print(Log log) { log.info(print()); lastPrintoutNow(); }
@Override public void validate(String name, String value) throws ParameterException { convert(value); } }
@Override public void handleGlobalError(OperationResult currentResult) { operation.finish(); } };
protected void handleResultOnFinish(OperationStatus operation, String finishMessage) { OperationResult result = operation.getResult(); result.recomputeStatus(); if (result.isAcceptable()) { log.info("{} in {}s. {}", finishMessage, NinjaUtils.DECIMAL_FORMAT.format(operation.getTotalTime()), operation.print()); } else { log.error("{} in {}s with some problems, reason: {}. {}", finishMessage, NinjaUtils.DECIMAL_FORMAT.format(operation.getTotalTime()), result.getMessage(), operation.print()); if (context.isVerbose()) { log.error("Full result\n{}", result.debugDumpLazily()); } } }
protected NinjaContext setupNinjaContext(String[] input) { JCommander jc = NinjaUtils.setupCommandLineParser(); jc.parse(input); NinjaContext context = new NinjaContext(jc); ConnectionOptions connection = NinjaUtils.getOptions(jc, ConnectionOptions.class); context.init(connection); return context; }
protected boolean shouldConsumerStop() { if (operation.isFinished()) { return true; } if (operation.isStarted()) { return false; } if (operation.isProducerFinished() && !queue.isEmpty()) { return false; } return true; }
public void init(NinjaContext context, T options) { this.context = context; this.options = options; LogTarget target = getInfoLogTarget(); log = new Log(target, this.context); this.context.setLog(log); ConnectionOptions connection = NinjaUtils.getOptions(this.context.getJc(), ConnectionOptions.class); this.context.init(connection); }
public boolean isVerbose() { BaseOptions base = NinjaUtils.getOptions(jc, BaseOptions.class); return base.isVerbose(); }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { long number = counter.incrementAndGet(); logRequest(number, request, body); ClientHttpResponse clientHttpResponse = execution.execute(request, body); traceResponse(number, clientHttpResponse); return clientHttpResponse; }
public void producerFinish() { if (state != State.STARTED) { throw new NinjaException("Can't set state " + State.PRODUCER_FINISHED + " for operation, previous state is was not " + State.STARTED); } debug("Operation: producer finished"); state = State.PRODUCER_FINISHED; }
public static ObjectFilter createObjectFilter(FileReference strFilter, NinjaContext context, Class<? extends ObjectType> objectClass) throws IOException, SchemaException { ObjectQuery query = createObjectQuery(strFilter, context, objectClass); return query != null ? query.getFilter() : null; }
public Log(LogTarget target, NinjaContext context) { this.target = target; this.context = context; init(); }
public void error(String message, Object... args) { error(message, null, args); }
public static <T> T getProxy(Class<T> type, Supplier<T> factory) { return (T) Proxy.newProxyInstance(ProxyCreator.class.getClassLoader(), new Class<?>[]{type}, new LazyInvocationHandler<>(factory)); }
private void debug(String message) { Log log = context.getLog(); log.debug(message); } }
@Override public void validate(String name, String value) throws ParameterException { if (value == null) { return; } Set<ObjectTypes> types = getType(value); if (types.isEmpty()) { throw new ParameterException("Unknown value " + value + " for option " + name); } }
public Charset getCharset() { BaseOptions base = NinjaUtils.getOptions(jc, BaseOptions.class); String charset = base.getCharset(); return Charset.forName(charset); }
public void start() { if (state != State.NOT_STARTED) { throw new NinjaException("Can't start operation, previous state is was not " + State.NOT_STARTED); } debug("Operation: started"); startTime = System.currentTimeMillis(); state = State.STARTED; }
@Override public void execute() throws Exception { String oid = options.getOid(); if (oid != null) { deleteByOid(); } else { ObjectQuery query = NinjaUtils.createObjectQuery(options.getFilter(), context, ObjectType.class); deleteByFilter(query); } }
public void finish() { if (state == State.NOT_STARTED) { throw new NinjaException("Can't finish operation, previous state was " + State.NOT_STARTED); } debug("Operation: finished"); finishTime = System.currentTimeMillis(); state = State.FINISHED; }