Example usage for org.springframework.util Assert isInstanceOf

List of usage examples for org.springframework.util Assert isInstanceOf

Introduction

In this page you can find the example usage for org.springframework.util Assert isInstanceOf.

Prototype

public static void isInstanceOf(Class<?> type, @Nullable Object obj) 

Source Link

Document

Assert that the provided object is an instance of the provided class.

Usage

From source file:org.springframework.integration.x.gemfire.GemFireMessageBus.java

private void doRegisterProducer(final String name, MessageChannel moduleOutputChannel, MessageHandler handler) {
    Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
    EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler);
    consumer.setBeanName("outbound." + name);
    consumer.afterPropertiesSet();/*from   w w  w.  j ava  2s .  c  om*/
    addBinding(Binding.forProducer(moduleOutputChannel, consumer));
    consumer.start();
}

From source file:org.springframework.integration.x.gemfire.GemFireRPCMessaging.java

@Override
public void execute(FunctionContext functionContext) {
    Assert.isInstanceOf(GemFireMessage.class, functionContext.getArguments());
    GemFireMessage gemFireMessage = (GemFireMessage) functionContext.getArguments();

    if (logger.isDebugEnabled()) {
        logger.debug("GemFireRPCMessaging.receive " + "\n\tgemFireMessage = " + gemFireMessage
                + "\n\tmessageProducer = " + messageProducer + "\n\tmessageProducer.get() = "
                + messageProducer.get(gemFireMessage.getChannelName()));
    }/*from w w w  .  ja  v a 2 s . c o  m*/
    GemFireMessageProducerSupport producerSupport = messageProducer.get(gemFireMessage.getChannelName());
    if (producerSupport != null) {
        Message message = gemFireMessage.getPayload();
        message = MessageBuilder.fromMessage(message).build();
        GemFireMessageProducerSupport handler = messageProducer.get(gemFireMessage.getChannelName());
        handler.pushMessage(message);
    }
    functionContext.getResultSender().lastResult(1);
}

From source file:org.springframework.integration.x.rabbit.RabbitChannelRegistry.java

@Override
public void createOutbound(final String name, MessageChannel moduleOutputChannel, boolean aliasHint) {
    Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
    MessageHandler handler = new CompositeHandler(name);
    EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler);
    consumer.setBeanName("outbound." + name);
    consumer.afterPropertiesSet();// w w w  .j ava  2 s . co  m
    this.lifecycleBeans.add(consumer);
    consumer.start();
}

From source file:org.springframework.integration.x.rabbit.RabbitMessageBus.java

private void doRegisterProducer(final String name, MessageChannel moduleOutputChannel, MessageHandler delegate,
        String replyTo) {//www . j av  a  2  s .com
    Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
    MessageHandler handler = new SendingHandler(delegate, replyTo);
    EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler);
    consumer.setBeanName("outbound." + name);
    consumer.afterPropertiesSet();
    addBinding(Binding.forProducer(moduleOutputChannel, consumer));
    consumer.start();
}

From source file:org.springframework.integration.x.rabbit.RabbitMessageBus.java

@Override
public void bindRequestor(String name, MessageChannel requests, MessageChannel replies) {
    if (logger.isInfoEnabled()) {
        logger.info("binding requestor: " + name);
    }//from w  w  w. java  2 s  . c  o m
    Assert.isInstanceOf(SubscribableChannel.class, requests);
    String queueName = name + ".requests";
    AmqpOutboundEndpoint queue = this.buildOutboundEndpoint(queueName);

    String replyQueueName = name + ".replies." + this.getIdGenerator().generateId();
    this.doRegisterProducer(name, requests, queue, replyQueueName);
    Queue replyQueue = new Queue(replyQueueName, false, false, true); // auto-delete
    this.rabbitAdmin.declareQueue(replyQueue);
    // register with context so it will be redeclared after a connection failure
    this.autoDeclareContext.getBeanFactory().registerSingleton(replyQueueName, replyQueue);
    this.doRegisterConsumer(name, replies, replyQueue);
}

From source file:org.springframework.integration.x.redis.RedisChannelRegistry.java

@Override
public void outbound(final String name, MessageChannel channel) {
    Assert.isInstanceOf(SubscribableChannel.class, channel);
    MessageHandler handler = new CompositeHandler(name, this.redisTemplate.getConnectionFactory());
    EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) channel, handler);
    consumer.setBeanName("outbound." + name);
    consumer.afterPropertiesSet();/* w w w .  j  a  v  a 2s .c om*/
    this.lifecycleBeans.add(consumer);
    consumer.start();
}

From source file:org.springframework.jms.support.converter.obm.MarshallingMessageConverter.java

public Object fromMessage(Message message) throws JMSException, MessageConversionException {
    try {/*from w w w .  j  a  va 2 s.c o m*/
        Assert.isInstanceOf(BytesMessage.class, message);
        if (message instanceof BytesMessage) {
            BytesMessage bytesMessage = (BytesMessage) message;
            return unmarshalFromBytesMessage(this.payloadClass, bytesMessage, this.unmarshaller);
        }

    } catch (IOException ex) {
        throw new MessageConversionException("Could not access message content: " + message, ex);
    }
    return null;
}

From source file:org.springframework.messaging.simp.stomp.StompProtocolHandler.java

/**
 * Handle incoming WebSocket messages from clients.
 *///from w w  w  .  j a v a  2 s .  c o  m
public void handleMessageFromClient(WebSocketSession session, WebSocketMessage webSocketMessage,
        MessageChannel outputChannel) {

    try {
        Assert.isInstanceOf(TextMessage.class, webSocketMessage);
        String payload = ((TextMessage) webSocketMessage).getPayload();
        Message<?> message = this.stompMessageConverter.toMessage(payload);

        // TODO: validate size limits
        // http://stomp.github.io/stomp-specification-1.2.html#Size_Limits

        if (logger.isTraceEnabled()) {
            logger.trace("Processing STOMP message: " + message);
        }

        try {
            StompHeaderAccessor headers = StompHeaderAccessor.wrap(message);
            headers.setSessionId(session.getId());
            headers.setUser(session.getPrincipal());

            message = MessageBuilder.withPayloadAndHeaders(message.getPayload(), headers).build();

            if (SimpMessageType.CONNECT.equals(headers.getMessageType())) {
                handleConnect(session, message);
            }

            outputChannel.send(message);

        } catch (Throwable t) {
            logger.error("Terminating STOMP session due to failure to send message: ", t);
            sendErrorMessage(session, t);
        }

        // TODO: send RECEIPT message if incoming message has "receipt" header
        // http://stomp.github.io/stomp-specification-1.2.html#Header_receipt

    } catch (Throwable error) {
        sendErrorMessage(session, error);
    }
}

From source file:org.springframework.osgi.extender.internal.support.ExtenderConfiguration.java

protected void addDefaultDependencyFactories() {
    boolean debug = log.isDebugEnabled();

    // default JDK 1.4 processor
    dependencyFactories.add(0, new MandatoryImporterDependencyFactory());

    // load through reflection the dependency and injection processors if running on JDK 1.5 and annotation
    // processing is enabled
    if (processAnnotation) {
        // dependency processor
        Class<?> annotationProcessor = null;
        try {/* w w  w  . jav a  2 s.co m*/
            annotationProcessor = Class.forName(ANNOTATION_DEPENDENCY_FACTORY, false,
                    ExtenderConfiguration.class.getClassLoader());
        } catch (ClassNotFoundException cnfe) {
            log.warn("Spring DM annotation package not found, annotation processing disabled.", cnfe);
            return;
        }
        Object processor = BeanUtils.instantiateClass(annotationProcessor);
        Assert.isInstanceOf(OsgiServiceDependencyFactory.class, processor);
        dependencyFactories.add(1, (OsgiServiceDependencyFactory) processor);

        if (debug)
            log.debug("Succesfully loaded annotation dependency processor [" + ANNOTATION_DEPENDENCY_FACTORY
                    + "]");

        // add injection processor (first in line)
        postProcessors.add(0, new OsgiAnnotationPostProcessor());
        log.info("Spring-DM annotation processing enabled");
    } else {
        if (debug) {
            log.debug("Spring-DM annotation processing disabled; [" + ANNOTATION_DEPENDENCY_FACTORY
                    + "] not loaded");
        }
    }

}

From source file:org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.java

/**
 * Callback method during Spring bean initialization that will capture the fully-qualified name
 * of the GemFire cache {@link Region} used to manage Session state and register this SessionRepository
 * as a GemFire {@link com.gemstone.gemfire.cache.CacheListener}.
 *
 * Additionally, this method registers GemFire {@link Instantiator}s for the {@link GemFireSession}
 * and {@link GemFireSessionAttributes} types to optimize GemFire's instantiation logic on deserialization
 * using the data serialization framework when accessing the {@link Session}'s state stored in GemFire.
 *
 * @throws Exception if an error occurs during the initialization process.
 *//*from   w w w.  j ava 2 s .c om*/
public void afterPropertiesSet() throws Exception {
    GemfireOperations template = getTemplate();

    Assert.isInstanceOf(GemfireAccessor.class, template);

    Region<Object, ExpiringSession> region = ((GemfireAccessor) template).getRegion();

    this.fullyQualifiedRegionName = region.getFullPath();

    region.getAttributesMutator().addCacheListener(this);

    Instantiator.register(GemFireSessionInstantiator.create());
    Instantiator.register(GemFireSessionAttributesInstantiator.create());
}