This repository has been archived by the owner on Oct 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major refactoring of the code. Got rid of guard-specific annotations,…
… 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
1 parent
5474d2e
commit 4e21e63
Showing
36 changed files
with
958 additions
and
1,086 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
kite-lib/src/main/java/org/zkybase/kite/AbstractGuard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
kite-lib/src/main/java/org/zkybase/kite/GuardCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
71 changes: 34 additions & 37 deletions
71
...se/kite/annotation/GuardedByThrottle.java → ...main/java/org/zkybase/kite/GuardedBy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | ||
} |
44 changes: 0 additions & 44 deletions
44
kite-lib/src/main/java/org/zkybase/kite/circuitbreaker/CircuitBreakerCallback.java
This file was deleted.
Oops, something went wrong.
77 changes: 0 additions & 77 deletions
77
...main/java/org/zkybase/kite/circuitbreaker/interceptor/AnnotationCircuitBreakerSource.java
This file was deleted.
Oops, something went wrong.
85 changes: 0 additions & 85 deletions
85
.../src/main/java/org/zkybase/kite/circuitbreaker/interceptor/CircuitBreakerInterceptor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.