Code Monkey home page Code Monkey logo

Comments (4)

epappas avatar epappas commented on August 25, 2024

Ok, I found the issue; First the TestAction class must be in separate file or declared static, as at ReflectionUtils @ findConstructor() the candidate.getParameterTypes() returns a +1 length to the arguments.

I think the issue can be closed.

from jesque.

gresrun avatar gresrun commented on August 25, 2024

Yup, Java implicitly adds a parameter for the surrounding type to the constructors of non-static inner classes! This article explains it well.

from jesque.

hanishi avatar hanishi commented on August 25, 2024

What if you want to create a shared BlockingQueue reference with in run() method where queue.offer() should be performed with string value that the class is constructed with?

from jesque.

hanishi avatar hanishi commented on August 25, 2024
public abstract class AbstractDelayedMessageSource<T> extends IntegrationObjectSupport implements MessageSource, DisposableBean {

    private final Worker jesqueWorker;
    private final SynchronousQueue<T> queue = new SynchronousQueue<>();
    private final ObjectMapper objectMapper;


    protected AbstractDelayedMessageSource(Config config, ObjectMapper mapper) {
        this.jesqueWorker = new WorkerImpl(config, Arrays.asList("foo"),
                new MapBasedJobFactory(map(entry("MessageDispatcher", MessageDispatcher.class))));
        this.objectMapper = mapper;
    }

    @Override
    protected void onInit() throws Exception {
        super.onInit();
        Thread workerThread = new Thread(jesqueWorker);
        workerThread.start();
    }

    public void destroy() throws Exception {
        jesqueWorker.end(true);
    }

    @Override
    public Message<T> receive() {
        T payload = null;
        try {
            payload = queue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return this.getMessageBuilderFactory().withPayload(payload).build();
    }

    private T deserializeJsonString(String jsonString) {
        try {
            Class<T> type =(Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(), AbstractDelayedMessageSource.class);
            return objectMapper.readerFor(type).readValue(jsonString);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public class MessageDispatcher implements Runnable {
        private final String jsonString;

        public MessageDispatcher(String jsonString) {
            this.jsonString = jsonString;
        }

        @Override
        public void run() {

            T object = deserializeJsonString(jsonString);
            queue.offer(object);
        }
    }
}

Can this be done?

from jesque.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.