Skip to content

Commit

Permalink
Fixes #1518: Add annotation/prog API support
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Mar 18, 2014
1 parent dbf3e62 commit dc80a81
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2014 Jeanfrancois Arcand
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.atmosphere.annotation;

import org.atmosphere.config.AtmosphereAnnotation;
import org.atmosphere.config.service.BroadcasterCacheListenerService;
import org.atmosphere.cpr.AtmosphereFramework;
import org.atmosphere.cpr.BroadcasterCacheListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@AtmosphereAnnotation(BroadcasterCacheListenerService.class)
public class BroadcasterCacheListenererviceProcessor implements Processor<BroadcasterCacheListener> {

private static final Logger logger = LoggerFactory.getLogger(BroadcasterCacheListenererviceProcessor.class);

@Override
public void handle(AtmosphereFramework framework, Class<BroadcasterCacheListener> annotatedClass) {
try {
framework.addBroadcasterCacheListener(framework.newClassInstance(BroadcasterCacheListener.class, annotatedClass));
} catch (Exception e) {
logger.warn("", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2014 Jeanfrancois Arcand
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.atmosphere.config.service;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* An annotation for installing {@link org.atmosphere.cpr.BroadcasterListener}
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface BroadcasterCacheListenerService {
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public class AtmosphereFramework {
protected boolean externalizeDestroy = false;
protected AnnotationProcessor annotationProcessor = null;
protected final List<String> excludedInterceptors = new ArrayList<String>();
protected final LinkedList<BroadcasterCacheListener> broadcasterCacheListeners = new LinkedList<BroadcasterCacheListener>();

protected final Class<? extends AtmosphereInterceptor>[] defaultInterceptors = new Class[]{
// Add CORS support
Expand Down Expand Up @@ -2173,6 +2174,18 @@ public AtmosphereFramework addBroadcasterListener(BroadcasterListener b) {
return this;
}

/**
* Add {@link BroadcasterCacheListener} to the {@link BroadcasterCache}.
*/
public AtmosphereFramework addBroadcasterCacheListener(BroadcasterCacheListener b) {
broadcasterCacheListeners.add(b);
return this;
}

public List<BroadcasterCacheListener> broadcasterCacheListeners() {
return broadcasterCacheListeners;
}

/**
* Add a {@link BroadcasterCacheInspector} which will be associated with the defined {@link BroadcasterCache}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ private void configureBroadcasterCache() {
for (BroadcasterCacheInspector b : config.framework().inspectors()) {
broadcasterCache.inspector(b);
}

for (BroadcasterCacheListener l: config.framework().broadcasterCacheListeners()) {
broadcasterCache.addBroadcasterCacheListener(l);
}

} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit dc80a81

Please sign in to comment.