-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
200 additions
and
15 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...-boot-starter/src/main/java/com/alipay/sofa/runtime/api/component/ComponentLifeCycle.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,41 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.alipay.sofa.runtime.api.component; | ||
|
||
import com.alipay.sofa.runtime.api.ServiceRuntimeException; | ||
|
||
/** | ||
* Interface used to implemented by components who wants to do something when certain lifecycle event of the component. | ||
* | ||
* @author khotyn | ||
* @since 2.6.0 | ||
*/ | ||
public interface ComponentLifeCycle { | ||
/** | ||
* Component lifecycle event occurred when component is activated. | ||
* | ||
* @throws ServiceRuntimeException | ||
*/ | ||
void activate() throws ServiceRuntimeException; | ||
|
||
/** | ||
* Component lifecycle event occurred when component is activated. | ||
* | ||
* @throws ServiceRuntimeException | ||
*/ | ||
void deactivate() throws ServiceRuntimeException; | ||
} |
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
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
52 changes: 52 additions & 0 deletions
52
...arter/src/test/java/com/alipay/sofa/runtime/beans/impl/ComponentLifeCycleServiceImpl.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,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.alipay.sofa.runtime.beans.impl; | ||
|
||
import com.alipay.sofa.runtime.api.ServiceRuntimeException; | ||
import com.alipay.sofa.runtime.api.component.ComponentLifeCycle; | ||
import com.alipay.sofa.runtime.beans.service.LifeCycleService; | ||
|
||
/** | ||
* | ||
* @author ruoshan | ||
* @since 2.6.0 | ||
*/ | ||
public class ComponentLifeCycleServiceImpl implements LifeCycleService, ComponentLifeCycle { | ||
|
||
private boolean activated; | ||
private boolean deactivated; | ||
|
||
@Override | ||
public void activate() throws ServiceRuntimeException { | ||
activated = true; | ||
} | ||
|
||
@Override | ||
public void deactivate() throws ServiceRuntimeException { | ||
deactivated = true; | ||
} | ||
|
||
@Override | ||
public boolean isActivated() { | ||
return activated; | ||
} | ||
|
||
@Override | ||
public boolean isDeactivated() { | ||
return deactivated; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...fa-boot-starter/src/test/java/com/alipay/sofa/runtime/beans/service/LifeCycleService.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,29 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.alipay.sofa.runtime.beans.service; | ||
|
||
/** | ||
* | ||
* @author ruoshan | ||
* @since 2.6.0 | ||
*/ | ||
public interface LifeCycleService { | ||
|
||
boolean isActivated(); | ||
|
||
boolean isDeactivated(); | ||
} |
57 changes: 57 additions & 0 deletions
57
...r/src/test/java/com/alipay/sofa/runtime/integration/component/ComponentLifeCycleTest.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,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 com.alipay.sofa.runtime.integration.component; | ||
|
||
import com.alipay.sofa.runtime.beans.service.LifeCycleService; | ||
import com.alipay.sofa.runtime.integration.base.SofaBootTestApplication; | ||
import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
/** | ||
* @author ruoshan | ||
* @since 2.6.0 | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = SofaBootTestApplication.class) | ||
public class ComponentLifeCycleTest { | ||
|
||
@Autowired | ||
private LifeCycleService lifeCycleService; | ||
|
||
@Autowired | ||
private SofaRuntimeContext sofaRuntimeContext; | ||
|
||
@Test | ||
public void testActivated() { | ||
Assert.assertTrue(lifeCycleService.isActivated()); | ||
} | ||
|
||
@Test | ||
@DirtiesContext | ||
public void testDeactivated() { | ||
Assert.assertFalse(lifeCycleService.isDeactivated()); | ||
sofaRuntimeContext.getComponentManager().shutdown(); | ||
Assert.assertTrue(lifeCycleService.isDeactivated()); | ||
} | ||
|
||
} |
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