Skip to content

Commit

Permalink
Refactor Server ability init login with SPI. (alibaba#7174)
Browse files Browse the repository at this point in the history
* Move ability classes.

* Add ServerAbilityInitializer and RemoteAbilityInitializer

* Add NamingAbilityInitializer.

* Use ServerAbilityInitializer replace old init ability.

* For pmd.
  • Loading branch information
KomachiSion authored Nov 4, 2021
1 parent f51985e commit 76aeb18
Show file tree
Hide file tree
Showing 23 changed files with 417 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@

package com.alibaba.nacos.api.ability;

import com.alibaba.nacos.api.config.ClientConfigAbility;
import com.alibaba.nacos.api.naming.ClientNamingAbility;
import com.alibaba.nacos.api.config.ability.ClientConfigAbility;
import com.alibaba.nacos.api.naming.ability.ClientNamingAbility;
import com.alibaba.nacos.api.remote.ability.ClientRemoteAbility;

import java.io.Serializable;

/**
* abilities of nacos client.
*
* @author liuzunfei
* @version $Id: ClientAbilities.java, v 0.1 2021年01月24日 00:09 AM liuzunfei Exp $
*/
public class ClientAbilities {
public class ClientAbilities implements Serializable {

private static final long serialVersionUID = -3590789441404549261L;

private ClientRemoteAbility remoteAbility = new ClientRemoteAbility();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package com.alibaba.nacos.api.ability;

import com.alibaba.nacos.api.config.ServerConfigAbility;
import com.alibaba.nacos.api.naming.ServerNamingAbility;
import com.alibaba.nacos.api.config.ability.ServerConfigAbility;
import com.alibaba.nacos.api.naming.ability.ServerNamingAbility;
import com.alibaba.nacos.api.remote.ability.ServerRemoteAbility;

import java.io.Serializable;
import java.util.Objects;
Expand All @@ -30,6 +31,8 @@
*/
public class ServerAbilities implements Serializable {

private static final long serialVersionUID = -2120543002911304171L;

private ServerRemoteAbility remoteAbility = new ServerRemoteAbility();

private ServerConfigAbility configAbility = new ServerConfigAbility();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.nacos.api.ability.initializer;

/**
* Nacos ability initializer.
*
* @author xiweng.yy
*/
public interface AbilityInitializer<A> {

/**
* Initialize target type abilities content.
*
* @param abilities abilities
*/
void initialize(A abilities);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.api.config;
package com.alibaba.nacos.api.config.ability;

/**
* config abilities of nacos client.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.api.config;
package com.alibaba.nacos.api.config.ability;

import java.io.Serializable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.api.naming;
package com.alibaba.nacos.api.naming.ability;

/**
* naming abilities of nacos client.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.api.naming;
package com.alibaba.nacos.api.naming.ability;

import java.io.Serializable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.api.ability;
package com.alibaba.nacos.api.remote.ability;

/**
* remote abilities of nacos client.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.api.ability;
package com.alibaba.nacos.api.remote.ability;

import java.io.Serializable;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.api.naming;
package com.alibaba.nacos.api.naming.ability;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.nacos.core.ability;

import com.alibaba.nacos.api.ability.ServerAbilities;

/**
* Server ability initializer for remote.
*
* @author xiweng.yy
*/
public class RemoteAbilityInitializer implements ServerAbilityInitializer {

@Override
public void initialize(ServerAbilities abilities) {
abilities.getRemoteAbility().setSupportRemoteConnection(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.nacos.core.ability;

import com.alibaba.nacos.api.ability.ServerAbilities;
import com.alibaba.nacos.api.ability.initializer.AbilityInitializer;

/**
* Nacos server ability initializer.
*
* @author xiweng.yy
*/
public interface ServerAbilityInitializer extends AbilityInitializer<ServerAbilities> {

/**
* Initialize server abilities content.
*
* @param abilities server abilities
*/
@Override
void initialize(ServerAbilities abilities);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* 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 com.alibaba.nacos.core.ability;

import com.alibaba.nacos.common.spi.NacosServiceLoader;
import com.alibaba.nacos.core.utils.Loggers;

import java.util.Collection;
import java.util.HashSet;

/**
* Nacos server ability initializer holder.
*
* @author xiweng.yy
*/
public class ServerAbilityInitializerHolder {

private static final ServerAbilityInitializerHolder INSTANCE = new ServerAbilityInitializerHolder();

private final Collection<ServerAbilityInitializer> initializers;

private ServerAbilityInitializerHolder() {
initializers = new HashSet<>();
for (ServerAbilityInitializer each : NacosServiceLoader.load(ServerAbilityInitializer.class)) {
Loggers.CORE.info("Load {} for ServerAbilityInitializer", each.getClass().getCanonicalName());
initializers.add(each);
}
}

public static ServerAbilityInitializerHolder getInstance() {
return INSTANCE;
}

public Collection<ServerAbilityInitializer> getInitializers() {
return initializers;
}
}
Loading

0 comments on commit 76aeb18

Please sign in to comment.