private void assertNotFrozen() { if (frozen) { throw new TentackleRuntimeException("time is frozen"); } }
String msg = super.getMessage(); if (session != null || identifiable != null) { msg += " {";
/** * Asserts that end ist valid. * <p> * The end is valid if {@link #end()} has been invoked. */ protected void assertDurationValid() { if (!durationValid) { throw new TentackleRuntimeException("duration not valid"); } }
private void assertNotFrozen() { if (frozen) { throw new TentackleRuntimeException("timestamp is frozen"); } }
private void checkPort(int port) { if (port < -1 || (port > 0 && port < 1024)) { throw new TentackleRuntimeException("illegal port number " + port + ". Possible values: -1, 0, >= 1024"); } }
private void assertNotfrozen() { if (frozen) { throw new TentackleRuntimeException("binary is frozen"); } }
private void assertNotFrozen() { if (frozen) { throw new TentackleRuntimeException("date is frozen"); } }
@Override public ExpirationSet clone() { try { return (ExpirationSet) super.clone(); } catch (CloneNotSupportedException ex) { throw new TentackleRuntimeException("clone failed", ex); } } }
@Override public IdSerialTuple clone() { try { return (IdSerialTuple) super.clone(); } catch (CloneNotSupportedException ex) { throw new TentackleRuntimeException("clone failed", ex); } }
/** * Checks that the provider really implements the given service. * * @param provider the provider * @param service the service * @param url the url */ private void checkProvider(Class<?> provider, Class<?> service, URL url) { if (!service.isAssignableFrom(provider)) { throw new TentackleRuntimeException( "provider '" + provider + "' does not implement '" + service + "', configured in " + url); } }
/** * Gets the cloned collection. * * @return the cloned collection */ @SuppressWarnings("unchecked") protected Collection<E> clonedCollection() { if (notCloned) { try { collection = (Collection<E>) cloneMethod.invoke(collection); notCloned = false; } catch (InvocationTargetException | IllegalAccessException ex) { throw new TentackleRuntimeException("cloning collection failed"); } } return collection; }
@Override public void setChainedInterceptor(Interceptor chainedInterceptor) { this.chainedInterceptor = chainedInterceptor; try { chainedMethod = chainedInterceptor.getClass().getMethod("invoke", Object.class, Method.class, Object[].class); } catch (NoSuchMethodException | SecurityException e) { throw new TentackleRuntimeException("cannot determine the 'invoke' method of the chained interceptor " + chainedInterceptor.getClass().getName(), e); } }
private static void checkDir(File dir) { if (!dir.exists()) { if (dir.mkdirs()) { LOGGER.info("created directory {0}", dir::getAbsolutePath); } else { throw new TentackleRuntimeException("couldn't create directory " + dir.getAbsolutePath()); } } if (!dir.canWrite()) { throw new TentackleRuntimeException("directory " + dir.getAbsolutePath() + " is not writable"); } }
@Override public void execute(Runnable command) { FutureTask<Void> task = new FutureTask<>(command, null); executor.execute(task); for (;;) { try { task.get(); // this will block until excecution has finished break; } catch (InterruptedException ix) { // interrupted: next round will catch result } catch (ExecutionException ex) { throw new TentackleRuntimeException("blocking execution failed", ex); } } } }
@Override public void discardSnapshot(TrackedList<E> snapshot) { int index = getSnapshotIndex(snapshot); if (index >= 0) { snapshots.remove(index); } else { throw new TentackleRuntimeException(MSG_NOT_MY_SNAPSHOT); } }
/** * Asserts that a thread local Locale is set.<br> * @throws TentackleRuntimeException if thread-local locale is null */ public void assertCurrentLocaleValid() { if (getCurrentLocale() == null) { throw new TentackleRuntimeException("no thread local Locale"); } }
/** * Registers the application.<br> * Makes sure that only one application is running at a time. * Should be invoked in the start-method. * <p> * Throws TentackleRuntimeException if an application is already running. */ protected void register() { synchronized(AbstractApplication.class) { // not getClass() because this applies to all kinds of applications! if (running != null) { throw new TentackleRuntimeException(MessageFormat.format(AppCoreBundle.getString("APPLICATION {0} ALREADY RUNNING"), running)); } running = this; } }
/** * Finds the first service configurations by service name.<br> * If similar configurations appear more than once on the classpath, the * first is returned. Useful to override service default implementations. * * @param serviceName the service name, usually a classname * @return the service configuation entry */ @Override public synchronized Map.Entry<String,URL> findFirstServiceConfiguration(String serviceName) { Map<String,URL> services = findServiceConfigurations(serviceName); if (services.isEmpty()) { throw new TentackleRuntimeException("service '" + serviceName + "' not found"); } return services.entrySet().iterator().next(); }
/** * Unregisters the application.<br> * Makes sure that only one application is running at a time. * Should be invoked in the stop-method. * <p> * Throws TentackleRuntimeException if no application is running. */ protected void unregister() { synchronized(AbstractApplication.class) { // not getClass() because this applies to all kinds of applications! if (running != null) { if (running != this) { throw new TentackleRuntimeException(MessageFormat.format(AppCoreBundle.getString("APPLICATION {0} IS NOT RUNNING"), this)); } running = null; } } }
/** * Handles the invocation exception. * <p> * The default implementation throws a {@link TentackleRuntimeException}. * * @param thrbl the exception * @param method the failed method * @param args the visited object plus optional parameters */ protected void handleException(Throwable thrbl, Method method, Object... args) { String message = "invocation of " + method + " failed for "; try { message += StringHelper.objectArrayToString(args, ", "); } catch (RuntimeException re) { message += "? -> " + re.getMessage(); } throw new TentackleRuntimeException(message, thrbl); }