Giter VIP home page Giter VIP logo

Comments (3)

jfarcand avatar jfarcand commented on May 28, 2024

@surajbhosale4933 Please update with an app/test case that demonstrate the issue. Please test with the latest version of Atmosphere as you version is really old and unsupported. Re-open one you have it.

from atmosphere.

surajbhosale4933 avatar surajbhosale4933 commented on May 28, 2024

@jfarcand I tried with update latest version of atmosphere-runtime (2.7.9) and atmosphere-spring(2.6.5), but still facing atmosphere removal issue from framework automatically. Our example is like:
from
Client Side:
uri = serverId+"/sb/test/msg";
Socket socket = getClient().create(options);
socket.on("message", new Function<List>() {
@OverRide
public void on(List messages) {
processMessages(messages);
}
}).on(Event.REOPENED.name(), new Function<List>() {
@OverRide
public void on(List messages) {
processMessages(messages);
}
}).on(new Function() {
@OverRide
public void on(Throwable t) {
if(connected) {
final LinkedHashMap<ReportKey, Object> map = new LinkedHashMap<>();
map.put(ReportKey.URL, uri);
map.put(ReportKey.DATE_TIME, System.currentTimeMillis());
map.put(ReportKey.REASON, t.getMessage());
map.put(ReportKey.CLIENT_ID, clientUuid);
showDisconnectMsg();
}

            	 String authErrorMsg  = "401 response received, but no WWW-Authenticate header was present";
            	
            	 if(t.getMessage().contains(authErrorMsg) && needAuth){
            		 // Means auth error from server on reconnecting.
            	 }
                connected = Boolean.FALSE;
                attachedToServerInfo.setConnected(false);
                logger.error("Connection refused by Atmosphere Server exception is " + t);
            }
        }).on(Event.CLOSE.name(), new Function<String>() {
            @Override
            public void on(String t) {
            	logger.trace("Connection closed");
            }
        }).on(Event.OPEN.name(), new Function<String>() {
            @Override
            public void on(String t) {
            	connected = Boolean.TRUE;
                final LinkedHashMap<ReportKey, Object> map = new LinkedHashMap<>();
                map.put(ReportKey.URL, uri);
                map.put(ReportKey.DATE_TIME, System.currentTimeMillis());
                map.put(ReportKey.CLIENT_ID, clientUuid);
                logger.trace("Connection opened");
                infoMessage.setVisible(false);
                if (flag) {
					flag = Boolean.FALSE;
					attachedToServerInfo.setConnected(false);
				}
				if (!attachedToServerInfo.isConnected()) {
					attachedToServerInfo.setConnected(true);
					infoMessage.setIsDispose(true);
				}
            }
         }).open(**getRequestBuilder**(uri, this.serverToken).build());

private RequestBuilder getRequestBuilder(String uri, String token) throws Exception {
RequestBuilder request = getClient().newRequestBuilder()
.method(Request.METHOD.GET)
.uri(uri)
.enableProtocol(false)
.trackMessageLength(false)
.header("X-Atmosphere-tracking-id", clientUuid.toString())
.header(RequestManager.HEADER_NAME, token)
.encoder(new Encoder<Message, String>() {
@OverRide
public String encode(Message data) {
try {
return mapper.writeValueAsString(data);
} catch (IOException e) {
logger.error("Error while encoder message " + e.getMessage());
throw new RuntimeException(e);
}
}
})
.decoder(new Decoder<String, List>() {
@OverRide
public List decode(Event type, String data) {
return processStringResponse(type, data);
}
}).transport(Request.TRANSPORT.SSE);
return request;
}

Server Side:

@SBManagedService(path = "/sb/test/msg", atmosphereConfig = {MAX_INACTIVE + "=120000", UUIDBROADCASTERCACHE_CLIENT_IDLETIME + "=120"})
public class AtmosphereController {
}

@target({ElementType.TYPE})
@retention(RetentionPolicy.RUNTIME)
public @interface SBManagedService {
String path() default "/";
public Class<? extends AtmosphereResourceEventListener>[] listeners() default {};
Class<? extends Broadcaster> broadcaster() default DefaultBroadcaster.class;
Class<? extends AtmosphereInterceptor>[] interceptors() default {};
String[] atmosphereConfig() default {};
Class<? extends BroadcasterCache> broadcasterCache() default NewSBBroadcasterCache.class;
Class<? extends BroadcastFilter>[] broadcastFilters() default {};
}

@AtmosphereAnnotation(SBManagedService.class)
public class SBManagedServiceProcessor implements Processor {
private static final Logger logger = LoggerFactory.getLogger(ManagedServiceProcessor.class);

@Override
public void handle(AtmosphereFramework framework, Class<Object> annotatedClass) {
    try {
        Class<?> aClass = annotatedClass;
        SBManagedService a = aClass.getAnnotation(SBManagedService.class);
        framework.setBroadcasterCacheClassName(a.broadcasterCache().getName());

        List<AtmosphereInterceptor> l = new LinkedList<AtmosphereInterceptor>();
        AnnotationUtil.defaultManagedServiceInterceptors(framework, l);

        atmosphereConfig(a.atmosphereConfig(), framework);
        filters(a.broadcastFilters(), framework);

        AtmosphereInterceptor aa = listeners(a.listeners(), framework);
        if (aa != null) {
            l.add(aa);
        }

        Object c = framework.newClassInstance(Object.class, aClass);
        AtmosphereHandler handler = framework.newClassInstance(ManagedAtmosphereHandler.class,
                        ManagedAtmosphereHandler.class).configure(framework.getAtmosphereConfig(), c);

        framework.filterManipulator(new BroadcasterConfig.FilterManipulator() {
            @Override
            public Object unwrap(Object o) {
                if (o != null && ManagedAtmosphereHandler.Managed.class.isAssignableFrom(o.getClass())) {
                    o = ManagedAtmosphereHandler.Managed.class.cast(o).object();
                }
                return o;
            }

            @Override
            public BroadcastFilter.BroadcastAction wrap(BroadcastFilter.BroadcastAction a, boolean wasWrapped) {
                if (wasWrapped) {
                    return new BroadcastFilter.BroadcastAction(a.action(), new ManagedAtmosphereHandler.Managed(a.message()));
                } else {
                    return a;
                }
            }
        });

        AnnotationUtil.interceptorsForManagedService(framework, Arrays.asList(a.interceptors()), l);
        framework.addAtmosphereHandler(a.path(), handler, broadcaster(framework, a.broadcaster(), a.path()), l);
    } catch (Throwable e) {
        logger.warn("", e);
    }
}

}

Earlier it was long-polling instead of SSE. there was no issue, but with SSE we are facing AtmosphereResource getting removed from framework after some time.

from atmosphere.

jfarcand avatar jfarcand commented on May 28, 2024

@surajbhosale4933 I really need a test case I can run unfortunately in order to help. I have extreme limited time. Hope you understand

from atmosphere.

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.