@Override public void registerDestructionCallback(String name, Runnable callback) { SimpAttributesContextHolder.currentAttributes().registerDestructionCallback(name, callback); }
@Override public String getConversationId() { return SimpAttributesContextHolder.currentAttributes().getSessionId(); }
@Override @Nullable public Object remove(String name) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); synchronized (simpAttributes.getSessionMutex()) { Object value = simpAttributes.getAttribute(name); if (value != null) { simpAttributes.removeAttribute(name); return value; } else { return null; } } }
@Override public boolean send(Message<?> message) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); assertThat(simpAttributes.getAttribute("name"), is("value")); return true; } @Override
@MessageMapping("/scope") public void scope() { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); assertThat(simpAttributes.getAttribute("name"), is("value")); this.method = "scope"; }
@Test public void currentAttributes() { SimpAttributesContextHolder.setAttributes(this.simpAttributes); assertThat(SimpAttributesContextHolder.currentAttributes(), sameInstance(this.simpAttributes)); }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); Object scopedObject = simpAttributes.getAttribute(name); if (scopedObject != null) { return scopedObject; } synchronized (simpAttributes.getSessionMutex()) { scopedObject = simpAttributes.getAttribute(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); simpAttributes.setAttribute(name, scopedObject); } return scopedObject; } }
@Test public void currentAttributesNone() { this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage(startsWith("No thread-bound SimpAttributes found")); SimpAttributesContextHolder.currentAttributes(); }
@Override public void registerDestructionCallback(String name, Runnable callback) { SimpAttributesContextHolder.currentAttributes().registerDestructionCallback(name, callback); }
@Override public String getConversationId() { return SimpAttributesContextHolder.currentAttributes().getSessionId(); }
@Override @Nullable public Object remove(String name) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); synchronized (simpAttributes.getSessionMutex()) { Object value = simpAttributes.getAttribute(name); if (value != null) { simpAttributes.removeAttribute(name); return value; } else { return null; } } }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); Object scopedObject = simpAttributes.getAttribute(name); if (scopedObject != null) { return scopedObject; } synchronized (simpAttributes.getSessionMutex()) { scopedObject = simpAttributes.getAttribute(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); simpAttributes.setAttribute(name, scopedObject); } return scopedObject; } }
@Autowired public Stomp(@Qualifier("clientOutboundChannel") MessageChannel clientChannel, SimpMessagingTemplate template) { SimpAttributes sa = SimpAttributesContextHolder.currentAttributes(); this.sessionId = sa.getSessionId(); this.template = template; this.clientChannel = clientChannel; }
@Override public void registerDestructionCallback(String name, Runnable callback) { SimpAttributesContextHolder.currentAttributes().registerDestructionCallback(name, callback); }
@Override public void registerDestructionCallback(String name, Runnable callback) { SimpAttributesContextHolder.currentAttributes().registerDestructionCallback(name, callback); }
@Override public String getConversationId() { return SimpAttributesContextHolder.currentAttributes().getSessionId(); }
@Override public String getConversationId() { return SimpAttributesContextHolder.currentAttributes().getSessionId(); }
@Override @Nullable public Object remove(String name) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); synchronized (simpAttributes.getSessionMutex()) { Object value = simpAttributes.getAttribute(name); if (value != null) { simpAttributes.removeAttribute(name); return value; } else { return null; } } }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); Object scopedObject = simpAttributes.getAttribute(name); if (scopedObject != null) { return scopedObject; } synchronized (simpAttributes.getSessionMutex()) { scopedObject = simpAttributes.getAttribute(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); simpAttributes.setAttribute(name, scopedObject); } return scopedObject; } }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); Object scopedObject = simpAttributes.getAttribute(name); if (scopedObject != null) { return scopedObject; } synchronized (simpAttributes.getSessionMutex()) { scopedObject = simpAttributes.getAttribute(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); simpAttributes.setAttribute(name, scopedObject); } return scopedObject; } }