@Override protected void endArray(String name) { try { hd.endElement("", "", name); } catch (SAXException e) { throw Exceptions.handle(e); } }
@Override public String toString() { try { StringWriter writer = new StringWriter(); XMLGenerator.writeXML(node, writer, Charsets.UTF_8.name(), true); return writer.toString(); } catch (Exception e) { Exceptions.handle(e); return node.toString(); } } }
@Override protected void endObject(String name) { try { hd.endElement("", "", name); } catch (SAXException e) { throw Exceptions.handle(e); } }
@Override protected void startArray(String name) { try { hd.startElement("", "", name, null); } catch (SAXException e) { throw Exceptions.handle(e); } }
@Override protected void writeProperty(String name, Object value) { try { hd.startElement("", "", name, null); if (value != null) { String val = value.toString(); hd.characters(val.toCharArray(), 0, val.length()); } hd.endElement("", "", name); } catch (SAXException e) { throw Exceptions.handle(e); } }
/** * Boilerplate method the directly handle the given exception without a special message or logger * * @param e the exception to handle * @return a <tt>HandledException</tt> which notifies surrounding calls that an error occurred, which has * already been taken care of. */ public static HandledException handle(Throwable e) { return handle().error(e).handle(); }
private void schedulerLoop() { while (running) { try { executeWaitingTasks(); idle(); } catch (Exception t) { Exceptions.handle(LOG, t); } } }
private static void createAndCollectClassLoadAction(String className, Class<?> clazz) { try { actions.add((ClassLoadAction) clazz.getDeclaredConstructor().newInstance()); } catch (Exception e) { Exceptions.handle() .error(e) .to(LOG) .withSystemErrorMessage("Failed to instantiate ClassLoadAction: %s - %s (%s)", className) .handle(); } }
private static void verifyUniquenessOfName(String name) { if (caches.containsKey(name)) { throw Exceptions.handle() .to(LOG) .withSystemErrorMessage("A cache named '%s' has already been created!", name) .handle(); } }
@Override public void readFromRequest(Entity entity, WebContext ctx) { try { getField().set(entity, transformFromRequest(getName(), ctx)); } catch (IllegalAccessException e) { Exceptions.handle(IndexAccess.LOG, e); } }
private static void startLifecycle(Startable lifecycle) { LOG.INFO("Starting: %s", lifecycle.getClass().getName()); try { lifecycle.started(); } catch (Exception e) { Exceptions.handle() .error(e) .to(LOG) .withSystemErrorMessage("Startup of: %s failed!", lifecycle.getClass().getName()) .handle(); } }
private static void stopLifecycle(Stoppable lifecycle) { LOG.INFO("Stopping: %s", lifecycle.getClass().getName()); try { lifecycle.stopped(); } catch (Exception e) { Exceptions.handle() .error(e) .to(LOG) .withSystemErrorMessage("Stop of: %s failed!", lifecycle.getClass().getName()) .handle(); } }
/** * Boilerplate method the directly handle the given exception without a special message * * @param log the logger used to log the exception * @param e the exception to handle * @return a <tt>HandledException</tt> which notifies surrounding calls that an error occurred, which has * already been taken care of. */ public static HandledException handle(Log log, Throwable e) { return handle().error(e).to(log).handle(); }
private void ensureReady() { if (!ready) { throw Exceptions.handle().to(LOG).withSystemErrorMessage("Index is not ready yet.").handle(); } }
private String getClusterState(ClusterStateResponse clusterStateResponse) { String state = ""; try (XContentBuilder clusterStateBuilder = XContentFactory.jsonBuilder()) { clusterStateBuilder.humanReadable(true).prettyPrint().startObject(); clusterStateResponse.getState().toXContent(clusterStateBuilder, ToXContent.EMPTY_PARAMS); clusterStateBuilder.endObject(); state = clusterStateBuilder.string(); } catch (IOException e) { Exceptions.handle(e); } return state; }
private String getClusterStateName(ClusterHealthResponse clusterHealthResponse) { try { return ClusterHealthStatus.fromValue(clusterHealthResponse.getStatus().value()).name(); } catch (IOException e) { Exceptions.handle(e); } return ""; }
@Override public Object eval(LocalRenderContext ctx, Expression[] args) { try (XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint()) { return ((ToXContent) args[0].eval(ctx)).toXContent(builder, ToXContent.EMPTY_PARAMS).string(); } catch (IOException e) { Exceptions.handle(e); } return ""; }
@Override public void readFromRequest(Entity entity, WebContext ctx) { try { if (ctx.get(getName()).isNull()) { return; } ((EntityRef<?>) getField().get(entity)).setId(ctx.get(getName()).asString()); } catch (IllegalAccessException e) { throw Exceptions.handle(IndexAccess.LOG, e); } }
protected Connection createConnection(String realm) { try { return oma.getDatabase(realm).getConnection(); } catch (SQLException e) { throw Exceptions.handle() .to(OMA.LOG) .error(e) .withSystemErrorMessage("Failed to open a database connection for realm '%s': %s (%s)", realm) .handle(); } }
private void clearScroll(SearchResponse searchResponse) { try { indexAccess.getClient() .prepareClearScroll() .addScrollId(searchResponse.getScrollId()) .execute() .actionGet(); } catch (Exception e) { Exceptions.handle(IndexAccess.LOG, e); } }