Search in sources :

Example 31 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacade method mutateEnvironmentConfigValue.

void mutateEnvironmentConfigValue(final String paramName, final Object newValue) {
    final ReplicatedEnvironment environment = _environment.get();
    if (environment != null) {
        try {
            final ReplicationMutableConfig oldConfig = environment.getRepMutableConfig();
            final ReplicationMutableConfig newConfig = oldConfig.setConfigParam(paramName, String.valueOf(newValue));
            environment.setRepMutableConfig(newConfig);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Node {} param {} has been changed to {}", _prettyGroupNodeName, paramName, newValue);
            }
        } catch (RuntimeException e) {
            RuntimeException handled = handleDatabaseException(String.format("Exception on setting %s", paramName), e);
            if (handled instanceof ConnectionScopedRuntimeException || handled instanceof ServerScopedRuntimeException) {
                throw handled;
            }
            throw new ConnectionScopedRuntimeException(String.format("Cannot set %s to %s on node %s", paramName, newValue, _prettyGroupNodeName), e);
        }
    } else {
        throw new ConnectionScopedRuntimeException(String.format("Cannot set %s to %s on node %s as environment does not currently exists", paramName, newValue, _prettyGroupNodeName));
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 32 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacade method setCacheSizeInternal.

void setCacheSizeInternal(long cacheSize) {
    final ReplicatedEnvironment environment = _environment.get();
    if (environment != null) {
        try {
            final EnvironmentMutableConfig oldConfig = environment.getMutableConfig();
            final EnvironmentMutableConfig newConfig = oldConfig.setCacheSize(cacheSize);
            environment.setMutableConfig(newConfig);
            LOGGER.debug("Node {} cache size has been changed to {}", _prettyGroupNodeName, cacheSize);
        } catch (RuntimeException e) {
            RuntimeException handled = handleDatabaseException("Exception on setting cache size", e);
            if (handled instanceof ConnectionScopedRuntimeException || handled instanceof ServerScopedRuntimeException) {
                throw handled;
            }
            throw new ConnectionScopedRuntimeException("Cannot set cache size to " + cacheSize + " on node " + _prettyGroupNodeName, e);
        }
    } else {
        throw new ConnectionScopedRuntimeException("Cannot set cache size to " + cacheSize + " on node " + _prettyGroupNodeName + " as environment does not exist");
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 33 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class AbstractServerMessageImpl method decrementReference.

/**
 * Thread-safe. This will decrement the reference count and when it reaches zero will remove the message from the
 * message store.
 */
private void decrementReference() {
    boolean updated;
    do {
        int count = _refCountUpdater.get(this);
        int newCount = count - 1;
        if (newCount > 0) {
            updated = _refCountUpdater.compareAndSet(this, count, newCount);
        } else if (newCount == 0) {
            // set the reference count below 0 so that we can detect that the message has been deleted
            updated = _refCountUpdater.compareAndSet(this, count, -1);
            if (updated) {
                _handle.remove();
            }
        } else {
            throw new ServerScopedRuntimeException("Reference count for message id " + debugIdentity() + " has gone below 0.");
        }
    } while (!updated);
}
Also used : ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 34 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class AbstractConfiguredObject method attainState.

private ListenableFuture<Void> attainState(State desiredState) {
    final State currentState = getState();
    ListenableFuture<Void> returnVal;
    if (_attainStateFuture.isDone()) {
        _attainStateFuture = SettableFuture.create();
    }
    if (currentState != desiredState) {
        Method stateChangingMethod = getStateChangeMethod(currentState, desiredState);
        if (stateChangingMethod != null) {
            try {
                final SettableFuture<Void> stateTransitionResult = SettableFuture.create();
                ListenableFuture<Void> stateTransitionFuture = (ListenableFuture<Void>) stateChangingMethod.invoke(this);
                addFutureCallback(stateTransitionFuture, new FutureCallback<Void>() {

                    @Override
                    public void onSuccess(Void result) {
                        try {
                            if (getState() != currentState) {
                                notifyStateChanged(currentState, getState());
                            }
                            stateTransitionResult.set(null);
                        } catch (Throwable e) {
                            stateTransitionResult.setException(e);
                        } finally {
                            _attainStateFuture.set(AbstractConfiguredObject.this);
                        }
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        // state transition failed to attain desired state
                        // setting the _attainStateFuture, so, object relying on it could get the configured object
                        _attainStateFuture.set(AbstractConfiguredObject.this);
                        stateTransitionResult.setException(t);
                    }
                }, getTaskExecutor());
                returnVal = stateTransitionResult;
            } catch (IllegalAccessException e) {
                throw new ServerScopedRuntimeException("Unexpected access exception when calling state transition", e);
            } catch (InvocationTargetException e) {
                // state transition failed to attain desired state
                // setting the _attainStateFuture, so, object relying on it could get the configured object
                _attainStateFuture.set(this);
                Throwable underlying = e.getTargetException();
                if (underlying instanceof RuntimeException) {
                    throw (RuntimeException) underlying;
                }
                if (underlying instanceof Error) {
                    throw (Error) underlying;
                }
                throw new ServerScopedRuntimeException("Unexpected checked exception when calling state transition", underlying);
            }
        } else {
            returnVal = Futures.immediateFuture(null);
            _attainStateFuture.set(this);
        }
    } else {
        returnVal = Futures.immediateFuture(null);
        _attainStateFuture.set(this);
    }
    return returnVal;
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 35 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class AbstractContainer method getMaxDirectMemorySize.

static long getMaxDirectMemorySize() {
    long maxMemory = 0;
    try {
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        Class<?> hotSpotDiagnosticMXBeanClass = Class.forName("com.sun.management.HotSpotDiagnosticMXBean", true, systemClassLoader);
        Class<?> vmOptionClass = Class.forName("com.sun.management.VMOption", true, systemClassLoader);
        Object hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean((Class<? extends PlatformManagedObject>) hotSpotDiagnosticMXBeanClass);
        Method getVMOption = hotSpotDiagnosticMXBeanClass.getDeclaredMethod("getVMOption", String.class);
        Object vmOption = getVMOption.invoke(hotSpotDiagnosticMXBean, "MaxDirectMemorySize");
        Method getValue = vmOptionClass.getDeclaredMethod("getValue");
        String maxDirectMemoryAsString = (String) getValue.invoke(vmOption);
        maxMemory = Long.parseLong(maxDirectMemoryAsString);
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) {
        LOGGER.debug("Cannot determine direct memory max size using com.sun.management.HotSpotDiagnosticMXBean: " + e.getMessage());
    } catch (InvocationTargetException e) {
        throw new ServerScopedRuntimeException("Unexpected exception in evaluation of MaxDirectMemorySize with HotSpotDiagnosticMXBean", e.getTargetException());
    }
    if (maxMemory == 0) {
        Pattern maxDirectMemorySizeArgumentPattern = Pattern.compile("^\\s*-XX:MaxDirectMemorySize\\s*=\\s*(\\d+)\\s*([KkMmGgTt]?)\\s*$");
        RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
        List<String> inputArguments = RuntimemxBean.getInputArguments();
        boolean argumentFound = false;
        for (String argument : inputArguments) {
            Matcher matcher = maxDirectMemorySizeArgumentPattern.matcher(argument);
            if (matcher.matches()) {
                argumentFound = true;
                maxMemory = Long.parseLong(matcher.group(1));
                String unit = matcher.group(2);
                char unitChar = "".equals(unit) ? 0 : unit.charAt(0);
                switch(unitChar) {
                    case 'k':
                    case 'K':
                        maxMemory *= 1024l;
                        break;
                    case 'm':
                    case 'M':
                        maxMemory *= 1024l * 1024l;
                        break;
                    case 'g':
                    case 'G':
                        maxMemory *= 1024l * 1024l * 1024l;
                        break;
                    case 't':
                    case 'T':
                        maxMemory *= 1024l * 1024l * 1024l * 1024l;
                        break;
                    case 0:
                        // noop
                        break;
                    default:
                        throw new IllegalStateException("Unexpected unit character in MaxDirectMemorySize argument : " + argument);
                }
            // do not break; continue. Oracle and IBM JVMs use the last value when argument is specified multiple times
            }
        }
        if (maxMemory == 0) {
            if (argumentFound) {
                throw new IllegalArgumentException("Qpid Broker cannot operate with 0 direct memory. Please, set JVM argument MaxDirectMemorySize to non-zero value");
            } else {
                maxMemory = Runtime.getRuntime().maxMemory();
            }
        }
    }
    return maxMemory;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Method(java.lang.reflect.Method) RuntimeMXBean(java.lang.management.RuntimeMXBean) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) PlatformManagedObject(java.lang.management.PlatformManagedObject)

Aggregations

ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)45 IOException (java.io.IOException)17 GeneralSecurityException (java.security.GeneralSecurityException)10 Map (java.util.Map)10 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 URL (java.net.URL)9 InputStream (java.io.InputStream)8 HttpURLConnection (java.net.HttpURLConnection)8 ConnectionBuilder (org.apache.qpid.server.util.ConnectionBuilder)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)6 TrustStore (org.apache.qpid.server.model.TrustStore)6 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)6 IdentityResolverException (org.apache.qpid.server.security.auth.manager.oauth2.IdentityResolverException)6 Field (java.lang.reflect.Field)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3