use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class StartupSequence method initLogging.
/**
* Initialize the logging framework.
*
* <p>Logging can be configured by setting the property logging.url in the config
* section of the root configuration, to point to the location of a logging config file.
* TRAC uses Log4j2 as a backend for slf4j, so the logging config file must be a valid
* log4j2 config file. If no logging config is provided, messages will be logged
* to stdout.</p>
*
* <p>This method should be called immediately after calling initConfigPlugins(),
* since it uses the config loading mechanism which relies on those plugins being
* available.</p>
*
* @throws EStartup There was an error processing the logging config
*/
public void initLogging() {
// Logger configured using initStartupLogging
var log = LoggerFactory.getLogger(getClass());
var rootConfigMap = config.loadRootConfigObject(Map.class);
String loggingConfigUrl = lookupLoggingConfigUrl(rootConfigMap);
if (loggingConfigUrl != null && !loggingConfigUrl.isBlank()) {
var loggingConfig = config.loadConfigFile(loggingConfigUrl);
try (var configStream = new ByteArrayInputStream(loggingConfig.getBytes())) {
var configSource = new ConfigurationSource(configStream);
Configurator.initialize(getClass().getClassLoader(), configSource);
// Invalid logging configuration cause the startup sequence to bomb out
} catch (IOException e) {
// Unexpected error condition - IO error reading from a byte buffer
throw new EUnexpected(e);
}
} else {
log.info("Using default logging config");
}
log.info("Initialize logging...");
Configurator.reconfigure();
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class Bytes method toProtoBytes.
public static ByteString toProtoBytes(ByteBuf buf) {
try {
if (buf.nioBufferCount() == 1) {
var nioBuffer = buf.nioBuffer();
return ByteString.copyFrom(nioBuffer);
}
if (buf.nioBufferCount() > 1) {
var nioBuffers = buf.nioBuffers();
var byteStream = Arrays.stream(nioBuffers).map(ByteString::copyFrom).reduce(ByteString::concat);
if (byteStream.isEmpty())
throw new EUnexpected();
return byteStream.get();
}
if (buf.hasArray()) {
return UnsafeByteOperations.unsafeWrap(buf.array());
}
var bufCopy = new byte[buf.readableBytes()];
buf.readBytes(bufCopy);
return UnsafeByteOperations.unsafeWrap(bufCopy);
} finally {
buf.release();
}
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class LocalFileWriter method writeNextChunk.
private void writeNextChunk() {
ByteBuf chunk = null;
try {
if (chunkInProgress || chunkBuffer.isEmpty())
throw new EUnexpected();
chunkInProgress = true;
chunksRequested -= 1;
chunk = chunkBuffer.remove();
var offset = bytesReceived;
bytesReceived += chunk.readableBytes();
if (chunk.nioBufferCount() < 1)
throw new EUnexpected();
var nioChunk = chunk.nioBuffer();
channel.write(nioChunk, offset, chunk, writeHandler);
} catch (Exception e) {
if (chunk != null)
releaseBuffer(chunk);
gotError = true;
handleError(e, true);
}
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class ConfigParser method parseConfig.
public static <TConfig extends Message, B extends Message.Builder> TConfig parseConfig(ByteBuf configData, ConfigFormat configFormat, Class<TConfig> configClass) {
try {
var newBuilder = configClass.getMethod("newBuilder");
var builder = (TConfig.Builder) newBuilder.invoke(null);
var blankConfig = (TConfig) builder.build();
switch(configFormat) {
case PROTO:
return parseProtoConfig(configData, blankConfig);
case JSON:
return parseJsonConfig(configData, blankConfig);
case YAML:
return parseYamlConfig(configData, blankConfig);
default:
throw new EStartup(String.format("Unknown config format [%s]", configFormat));
}
} catch (InvalidProtocolBufferException e) {
throw new EStartup("Invalid config: " + e.getMessage(), e);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
// Error invoking reflective method for builder
throw new EUnexpected();
} finally {
configData.release();
}
}
use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.
the class Flows method concat.
public static <T> Flow.Publisher<T> concat(List<Flow.Publisher<T>> publishers) {
if (publishers.isEmpty())
throw new EUnexpected();
var concat = new ConcatProcessor<>(publishers);
publishers.get(0).subscribe(concat);
return concat;
}
Aggregations