private ConcurrentMap<LinkKey, Link_1_0<S,T>> getLinkRegistry(final Role role) { ConcurrentMap<LinkKey, Link_1_0<S,T>> linkRegistry; if (Role.SENDER == role) { linkRegistry = _sendingLinkRegistry; } else if (Role.RECEIVER == role) { linkRegistry = _receivingLinkRegistry; } else { throw new ServerScopedRuntimeException(String.format("Unsupported link role %s", role)); } return linkRegistry; }
throw new ServerScopedRuntimeException(e); throw new ServerScopedRuntimeException(cause); throw new ServerScopedRuntimeException(e);
public static byte[] getMD5(byte[] data) { MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new ServerScopedRuntimeException("MD5 not supported although Java compliance requires it"); } for (byte b : data) { md.update(b); } return md.digest(); }
@Override protected String createStoredPassword(final String password) { byte[] data = password.getBytes(StandardCharsets.UTF_8); MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new ServerScopedRuntimeException("MD5 not supported although Java compliance requires it"); } md.update(data); return Base64.getEncoder().encodeToString(md.digest()); }
public static String getInstalledProtocolsAsString() { Set<Protocol> installedProtocols = getInstalledProtocols(); ObjectMapper mapper = new ObjectMapper(); try(StringWriter output = new StringWriter()) { mapper.writeValue(output, installedProtocols); return output.toString(); } catch (IOException e) { throw new ServerScopedRuntimeException(e); } }
private synchronized void update() { if (_groupFile != null) { try { writeGroupFile(_groupFile); } catch (IOException e) { throw new ServerScopedRuntimeException("Unable to persist change to file " + _groupFile,e); } } }
private Class<? extends ConfiguredObject> calculateBestFitInterface() { Set<Class<? extends ConfiguredObject>> candidates = new HashSet<Class<? extends ConfiguredObject>>(); findBestFitInterface(getClass(), candidates); switch(candidates.size()) { case 0: throw new ServerScopedRuntimeException("The configured object class " + getClass().getSimpleName() + " does not seem to implement an interface"); case 1: return candidates.iterator().next(); default: ArrayList<Class<? extends ConfiguredObject>> list = new ArrayList<>(candidates); throw new ServerScopedRuntimeException("The configured object class " + getClass().getSimpleName() + " implements no single common interface which extends ConfiguredObject" + " Identified candidates were : " + Arrays.toString(list.toArray())); } }
private <X extends ConfiguredObject> void processDerivedAttribute(final Class<X> clazz, final SortedSet<ConfiguredObjectAttribute<?, ?>> attributeSet, final Method m) { DerivedAttribute annotation = m.getAnnotation(DerivedAttribute.class); if (!clazz.isInterface() || !ConfiguredObject.class.isAssignableFrom(clazz)) { throw new ServerScopedRuntimeException("Can only define DerivedAttributes on interfaces which extend " + ConfiguredObject.class.getSimpleName() + ". " + clazz.getSimpleName() + " does not meet these criteria."); } ConfiguredObjectAttribute<?, ?> attribute = new ConfiguredDerivedMethodAttribute<>(clazz, m, annotation); if (attributeSet.contains(attribute)) { attributeSet.remove(attribute); } attributeSet.add(attribute); }
private <X extends ConfiguredObject> void processManagedAttribute(final Class<X> clazz, final SortedSet<ConfiguredObjectAttribute<?, ?>> attributeSet, final Method m) { ManagedAttribute annotation = m.getAnnotation(ManagedAttribute.class); if (!clazz.isInterface() || !ConfiguredObject.class.isAssignableFrom(clazz)) { throw new ServerScopedRuntimeException("Can only define ManagedAttributes on interfaces which extend " + ConfiguredObject.class.getSimpleName() + ". " + clazz.getSimpleName() + " does not meet these criteria."); } ConfiguredObjectAttribute<?, ?> attribute = new ConfiguredAutomatedAttribute<>(clazz, m, annotation); if (attributeSet.contains(attribute)) { attributeSet.remove(attribute); } attributeSet.add(attribute); }
private static Class getRawType(Type t) { if(t instanceof Class) { return (Class)t; } else if(t instanceof ParameterizedType) { return (Class)((ParameterizedType)t).getRawType(); } else if(t instanceof TypeVariable) { Type[] bounds = ((TypeVariable)t).getBounds(); if(bounds.length == 1) { return getRawType(bounds[0]); } } throw new ServerScopedRuntimeException("Unable to process type when constructing configuration model: " + t); }
private <X extends ConfiguredObject> void processManagedStatistic(final Class<X> clazz, final SortedSet<ConfiguredObjectStatistic<?, ?>> statisticSet, final Method m) { ManagedStatistic statAnnotation = m.getAnnotation(ManagedStatistic.class); if (!clazz.isInterface() || !ConfiguredObject.class.isAssignableFrom(clazz)) { throw new ServerScopedRuntimeException("Can only define ManagedStatistics on interfaces which extend " + ConfiguredObject.class.getSimpleName() + ". " + clazz.getSimpleName() + " does not meet these criteria."); } ConfiguredObjectStatistic statistic = new ConfiguredObjectMethodStatistic(clazz, m, statAnnotation); if (statisticSet.contains(statistic)) { statisticSet.remove(statistic); } statisticSet.add(statistic); }
private <C extends Pluggable> Iterable<C> instancesOf(Class<C> clazz, boolean atLeastOne) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Iterator<C> serviceLoaderIterator = ServiceLoader.load(clazz, classLoader).iterator(); // create a new list so we can log the count List<C> serviceImplementations = new ArrayList<C>(); while(serviceLoaderIterator.hasNext()) { C next = serviceLoaderIterator.next(); if(!isDisabled(clazz, next) && isAvailable(next)) { serviceImplementations.add(next); } } if(atLeastOne && serviceImplementations.isEmpty()) { throw new ServerScopedRuntimeException("At least one implementation of " + clazz + " expected"); } LOGGER.debug("Found {} implementations of {}", serviceImplementations.size(), clazz); return serviceImplementations; }
void setPort(int port) { try { _delegate = new JMXServiceURL(_delegate.getProtocol(), _delegate.getHost(), port, _delegate.getURLPath()); } catch (MalformedURLException e) { throw new ServerScopedRuntimeException("Unexpected exception when updating port", e); } }
@Override public void onSuccess(final Object result) { State state = container.getState(); if (state == State.ACTIVE) { startupLogger.message(BrokerMessages.READY()); container.setEventLogger(eventLogger); returnVal.set(null); } else { returnVal.setException(new ServerScopedRuntimeException("Broker failed reach ACTIVE state (state is " + state + ")")); } }
public NonBlockingConnectionTLSDelegate(NonBlockingConnection parent, AmqpPort port) { _parent = parent; _sslEngine = createSSLEngine(port); _networkBufferSize = port.getNetworkBufferSize(); final int tlsPacketBufferSize = _sslEngine.getSession().getPacketBufferSize(); if (tlsPacketBufferSize > _networkBufferSize) { throw new ServerScopedRuntimeException("TLS implementation packet buffer size (" + tlsPacketBufferSize + ") is greater then broker network buffer size (" + _networkBufferSize + ")"); } _netInputBuffer = QpidByteBuffer.allocateDirect(_networkBufferSize); _applicationBuffer = QpidByteBuffer.allocateDirect(_networkBufferSize); _netOutputBuffer = QpidByteBuffer.allocateDirect(_networkBufferSize); }
@Override protected ListenableFuture<Void> onClose() { getBroker().removeChangeListener(_brokerChangeListener); if (_server != null) { try { logOperationalShutdownMessage(); _server.stop(); } catch (Exception e) { throw new ServerScopedRuntimeException("Failed to stop HTTP management", e); } } if (_jettyServerExecutor != null) { _jettyServerExecutor.shutdown(); } getBroker().getEventLogger().message(ManagementConsoleMessages.STOPPED(OPERATIONAL_LOGGING_NAME)); return Futures.immediateFuture(null); }
@Override public final void received(final QpidByteBuffer buf) { AccessController.doPrivileged((PrivilegedAction<Object>) () -> { updateLastReadTime(); try { onReceive(buf); } catch (StoreException e) { if (getAddressSpace().isActive()) { throw new ServerScopedRuntimeException(e); } else { throw new ConnectionScopedRuntimeException(e); } } return null; }, getAccessControllerContext()); }
private interface HoldMethod { boolean isHeld(MessageReference<?> message, long evalutaionTime); }
LinkRegistryImpl(final NamedAddressSpace addressSpace) { LinkStoreFactory storeFactory = null; Iterable<LinkStoreFactory> linkStoreFactories = new QpidServiceLoader().instancesOf(LinkStoreFactory.class); for (LinkStoreFactory linkStoreFactory : linkStoreFactories) { if (linkStoreFactory.supports(addressSpace) && (storeFactory == null || storeFactory.getPriority() < linkStoreFactory.getPriority())) { storeFactory = linkStoreFactory; } } if (storeFactory == null) { throw new ServerScopedRuntimeException("Cannot find suitable link store"); } _linkStore = storeFactory.create(addressSpace); }
private void expireEntry(final QueueEntry node) { ExpiryPolicy expiryPolicy = getExpiryPolicy(); long sizeWithHeader = node.getSizeWithHeader(); switch (expiryPolicy) { case DELETE: deleteEntry(node, () -> _queueStatistics.addToExpired(sizeWithHeader) ); break; case ROUTE_TO_ALTERNATE: routeToAlternate(node, () -> _queueStatistics.addToExpired(sizeWithHeader), q -> !((q instanceof AbstractQueue) && ((AbstractQueue) q).wouldExpire(node.getMessage()))); break; default: throw new ServerScopedRuntimeException("Unknown expiry policy: " + expiryPolicy + " this is a coding error inside Qpid"); } }