Skip to content
This repository has been archived by the owner on Oct 14, 2018. It is now read-only.

Commit

Permalink
Major refactoring of the code. Got rid of guard-specific annotations,…
Browse files Browse the repository at this point in the history
… callbacks, interceptors, config, replacing with general versions. This makes it much simpler to add new guards. Also now there is a @GuardedBy annotation that can take a list of guards, which means that now we can have multiple guards of the same type, such as multiple rate limiters for different timescales.
  • Loading branch information
williewheeler committed May 20, 2012
1 parent 5474d2e commit 4e21e63
Show file tree
Hide file tree
Showing 36 changed files with 958 additions and 1,086 deletions.
9 changes: 9 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
========================================================================================================================
[DONE]

Allow multiple breakers of a given type to be applied to a method. For example, we should be able to place multiple
rate-limiting throttles on a method: one allowing 60 requests per minute, and another allowing 1800 per hour. Right now
this isn't possible using the annotations. This would work:

@GuardedBy({ "messageServiceBreaker", "perMinuteRateLimitingThrottle", "perHourRateLimitingThrottle" })
========================================================================================================================
37 changes: 37 additions & 0 deletions kite-lib/src/main/java/org/zkybase/kite/AbstractGuard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2010 the original author or authors.
*
* 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.zkybase.kite;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.jmx.export.annotation.ManagedAttribute;

/**
* @version $Id$
* @author Willie Wheeler (willie.wheeler@gmail.com)
*/
public abstract class AbstractGuard implements Guard, BeanNameAware {
private String name;

@ManagedAttribute(description = "Guard name")
public String getName() { return name; }

/* (non-Javadoc)
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
@Override
public void setBeanName(String beanName) { this.name = beanName; }

}
28 changes: 28 additions & 0 deletions kite-lib/src/main/java/org/zkybase/kite/Guard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2010 the original author or authors.
*
* 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.zkybase.kite;


/**
* @author Willie Wheeler (willie.wheeler@gmail.com)
* @since 1.0
*/
public interface Guard {

String getName();

<T> T execute(GuardCallback<T> action) throws Throwable;
}
25 changes: 25 additions & 0 deletions kite-lib/src/main/java/org/zkybase/kite/GuardCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2010 the original author or authors.
*
* 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.zkybase.kite;

/**
* @author Willie Wheeler (willie.wheeler@gmail.com)
* @since 1.0
*/
public interface GuardCallback<T> {

T doInGuard() throws Throwable;
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
/*
* Copyright (c) 2010 the original author or authors.
*
* 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.zkybase.kite.annotation;

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;

/**
* Annotation indicating that the annotated class or method is guarded by the referenced throttle (i.e., the
* annotation's value).
*
* @author Willie Wheeler
* @since 1.0
*/
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface GuardedByThrottle {

String value() default "";
}
/*
* Copyright (c) 2010 the original author or authors.
*
* 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.zkybase.kite;

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;

/**
* @author Willie Wheeler (willie.wheeler@gmail.com)
* @since 1.0
*/
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface GuardedBy {

String[] value() default "";
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4e21e63

Please sign in to comment.