/** * Invokes the method and retrieves its return {@link Reply}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Reply} returned by the given method */ private Function<? super Method, AbilityExtension> returnExtension(Object obj) { return method -> { try { return (AbilityExtension) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add ability extension", TAG, e); throw propagate(e); } }; }
/** * Invokes the method and retrieves its return {@link Ability}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Ability} returned by the given method */ private Function<? super Method, Ability> returnAbility(Object obj) { return method -> { try { return (Ability) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add ability", TAG, e); throw propagate(e); } }; }
/** * Invokes the method and retrieves its return {@link Reply}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Reply} returned by the given method */ private Function<? super Method, Reply> returnReply(Object obj) { return method -> { try { return (Reply) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add reply", TAG, e); throw propagate(e); } }; }
} catch (IllegalStateException e) { BotLogger.error(TAG, "Duplicate names found while registering abilities. Make sure that the abilities declared don't clash with the reserved ones.", e); throw propagate(e);
/** * Gets the user with the specified username. If user was not found, the bot will send a message on Telegram. * * @param username the username of the required user * @param ctx the message context with the originating user * @return the id of the user */ protected int getUserIdSendError(String username, MessageContext ctx) { try { return getUser(username).getId(); } catch (IllegalStateException ex) { silent.send(getLocalizedMessage(USER_NOT_FOUND, ctx.user().getLanguageCode(), username), ctx.chatId()); throw propagate(ex); } }
@Override public void run() { try { wrapped.call(); } catch (Exception e) { Throwables.propagate(e); } } };
@Override public void run() { try { wrapped.call(); } catch (Exception e) { Throwables.propagate(e); } } };
@Override public void run() { try { wrapped.call(); } catch (Exception e) { Throwables.propagate(e); } } };
@Override public void run() { try { wrapped.call(); } catch (Exception e) { Throwables.propagate(e); } } };
@Override public void run() { try { delegate.run(); } catch (Throwable t) { setException(t); throw Throwables.propagate(t); } } }
@Override public void run() { try { delegate.run(); } catch (Throwable t) { setException(t); throw Throwables.propagate(t); } } }
@Override public void run() { try { delegate.run(); } catch (Throwable t) { setException(t); throw Throwables.propagate(t); } } }
@Override public void run() { try { delegate.run(); } catch (Throwable t) { setException(t); throw Throwables.propagate(t); } } }
public AdvancedSearchPanel(String id, IModel<Project> projectModel, IModel<String> revisionModel) { super(id); this.projectModel = projectModel; this.revisionModel = revisionModel; Class<? extends SearchOption> activeTab = WebSession.get().getMetaData(ACTIVE_TAB); if (activeTab != null) { try { option = activeTab.newInstance(); } catch (Exception e) { Throwables.propagate(e); } } }
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. * Otherwise, returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. * Otherwise, returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. * Otherwise, returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }
/** * Returns a default thread factory used to create new threads. * * <p>On AppEngine, returns {@code ThreadManager.currentRequestThreadFactory()}. * Otherwise, returns {@link Executors#defaultThreadFactory()}. * * @since 14.0 */ @Beta public static ThreadFactory platformThreadFactory() { if (!isAppEngine()) { return Executors.defaultThreadFactory(); } try { return (ThreadFactory) Class.forName("com.google.appengine.api.ThreadManager") .getMethod("currentRequestThreadFactory") .invoke(null); } catch (IllegalAccessException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (NoSuchMethodException e) { throw new RuntimeException("Couldn't invoke ThreadManager.currentRequestThreadFactory", e); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } }
private static Stream<Record> download(final Session session, final boolean dumpResources, final boolean dumpMentions, @Nullable final String id) throws Throwable { final List<URI> types = Lists.newArrayList(); if (dumpResources) { types.add(KS.RESOURCE); } if (dumpMentions) { types.add(KS.MENTION); } return Stream.concat(Stream.create(types) .transform( (final URI type) -> { LOGGER.info("Downloading {} data", type.getLocalName().toLowerCase()); try { final Retrieve retrieve = session.retrieve(type) .limit((long) Integer.MAX_VALUE) .timeout(7 * 24 * 60 * 60 * 1000L); // 1 week if (id != null) { retrieve.ids(new URIImpl(id)); } return retrieve.exec(); // return session.retrieve(type).limit((long) Integer.MAX_VALUE) // .timeout(24 * 60 * 60 * 1000L).exec(); } catch (final Throwable ex) { throw Throwables.propagate(ex); } }, 1)); }