Skip to content

Commit 097e762

Browse files
mercyblitzchickenlj
authored andcommitted
To add new module for Dubbo Event (#4099)
fixes #4096
1 parent d0d1a65 commit 097e762

File tree

73 files changed

+5158
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+5158
-24
lines changed

dubbo-all/pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,23 @@
500500
<optional>true</optional>
501501
</dependency>
502502

503+
<!-- 2.7.2 new modules -->
504+
<dependency>
505+
<groupId>org.apache.dubbo</groupId>
506+
<artifactId>dubbo-event</artifactId>
507+
<version>${project.version}</version>
508+
<scope>compile</scope>
509+
<optional>true</optional>
510+
</dependency>
511+
512+
<dependency>
513+
<groupId>org.apache.dubbo</groupId>
514+
<artifactId>dubbo-metadata</artifactId>
515+
<version>${project.version}</version>
516+
<scope>compile</scope>
517+
<optional>true</optional>
518+
</dependency>
519+
503520
<!-- Transitive dependencies -->
504521
<dependency>
505522
<groupId>org.springframework</groupId>
@@ -631,6 +648,10 @@
631648
<include>org.apache.dubbo:dubbo-metadata-report-nacos</include>
632649
<include>org.apache.dubbo:dubbo-serialization-native-hession</include>
633650
<include>org.apache.dubbo:dubbo-rpc-native-thrift</include>
651+
652+
<!-- 2.7.2 new modules -->
653+
<include>org.apache.dubbo:dubbo-event</include>
654+
<include>org.apache.dubbo:dubbo-metadata</include>
634655
</includes>
635656
</artifactSet>
636657
<transformers>
@@ -756,6 +777,19 @@
756777
<resource>META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory
757778
</resource>
758779
</transformer>
780+
<!-- @since 2.7.2 -->
781+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
782+
<resource>META-INF/dubbo/internal/org.apache.dubbo.event.EventDispatcher
783+
</resource>
784+
</transformer>
785+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
786+
<resource>META-INF/dubbo/internal/org.apache.dubbo.metadata.export.MetadataServiceExporter
787+
</resource>
788+
</transformer>
789+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
790+
<resource>META-INF/dubbo/internal/org.apache.dubbo.metadata.LocalMetadataService
791+
</resource>
792+
</transformer>
759793
</transformers>
760794
<filters>
761795
<filter>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.function;
18+
19+
import java.util.function.Consumer;
20+
import java.util.function.Function;
21+
22+
/**
23+
* {@link Consumer} with {@link Throwable}
24+
*
25+
* @param <T> the source type
26+
* @see Function
27+
* @see Throwable
28+
* @since 2.7.2
29+
*/
30+
@FunctionalInterface
31+
public interface ThrowableConsumer<T> {
32+
33+
/**
34+
* Applies this function to the given argument.
35+
*
36+
* @param t the function argument
37+
* @throws Throwable if met with any error
38+
*/
39+
void accept(T t) throws Throwable;
40+
41+
/**
42+
* Executes {@link ThrowableConsumer}
43+
*
44+
* @param t the function argument
45+
* @throws RuntimeException wrappers {@link Throwable}
46+
*/
47+
default void execute(T t) throws RuntimeException {
48+
try {
49+
accept(t);
50+
} catch (Throwable e) {
51+
throw new RuntimeException(e.getMessage(), e.getCause());
52+
}
53+
}
54+
55+
/**
56+
* Executes {@link ThrowableConsumer}
57+
*
58+
* @param t the function argument
59+
* @param consumer {@link ThrowableConsumer}
60+
* @param <T> the source type
61+
* @return the result after execution
62+
*/
63+
static <T> void execute(T t, ThrowableConsumer<T> consumer) {
64+
consumer.execute(t);
65+
}
66+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.function;
18+
19+
import java.util.function.Function;
20+
21+
/**
22+
* {@link Function} with {@link Throwable}
23+
*
24+
* @param <T> the source type
25+
* @param <R> the return type
26+
* @see Function
27+
* @see Throwable
28+
* @since 2.7.2
29+
*/
30+
@FunctionalInterface
31+
public interface ThrowableFunction<T, R> {
32+
33+
/**
34+
* Applies this function to the given argument.
35+
*
36+
* @param t the function argument
37+
* @return the function result
38+
* @throws Throwable if met with any error
39+
*/
40+
R apply(T t) throws Throwable;
41+
42+
/**
43+
* Executes {@link ThrowableFunction}
44+
*
45+
* @param t the function argument
46+
* @return the function result
47+
* @throws RuntimeException wrappers {@link Throwable}
48+
*/
49+
default R execute(T t) throws RuntimeException {
50+
R result = null;
51+
try {
52+
result = apply(t);
53+
} catch (Throwable e) {
54+
throw new RuntimeException(e.getCause());
55+
}
56+
return result;
57+
}
58+
59+
/**
60+
* Executes {@link ThrowableFunction}
61+
*
62+
* @param t the function argument
63+
* @param function {@link ThrowableFunction}
64+
* @param <T> the source type
65+
* @param <R> the return type
66+
* @return the result after execution
67+
*/
68+
static <T, R> R execute(T t, ThrowableFunction<T, R> function) {
69+
return function.execute(t);
70+
}
71+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.utils;
18+
19+
import java.io.Serializable;
20+
import java.util.List;
21+
22+
/**
23+
* The default implementation of {@link Page}
24+
*
25+
* @since 2.7.2
26+
*/
27+
public class DefaultPage<T> implements Page<T>, Serializable {
28+
29+
private static final long serialVersionUID = 1099331838954070419L;
30+
31+
private final int requestOffset;
32+
33+
private final int requestSize;
34+
35+
private int totalSize;
36+
37+
private List<T> data;
38+
39+
public DefaultPage(int requestOffset, int requestSize) {
40+
this.requestOffset = requestOffset;
41+
this.requestSize = requestSize;
42+
}
43+
44+
@Override
45+
public int getRequestOffset() {
46+
return requestOffset;
47+
}
48+
49+
@Override
50+
public int getRequestSize() {
51+
return requestSize;
52+
}
53+
54+
@Override
55+
public int getTotalSize() {
56+
return totalSize;
57+
}
58+
59+
public void setTotalSize(int totalSize) {
60+
this.totalSize = totalSize;
61+
}
62+
63+
@Override
64+
public List<T> getData() {
65+
return data;
66+
}
67+
68+
public void setData(List<T> data) {
69+
this.data = data;
70+
}
71+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.utils;
18+
19+
import java.util.List;
20+
21+
/**
22+
* The model class of pagination
23+
*
24+
* @since 2.7.2
25+
*/
26+
public interface Page<T> {
27+
28+
/**
29+
* Gets the offset of request
30+
*
31+
* @return positive integer
32+
*/
33+
int getRequestOffset();
34+
35+
/**
36+
* Gets the size of request for query
37+
*
38+
* @return positive integer
39+
*/
40+
int getRequestSize();
41+
42+
/**
43+
* Returns the total amount of elements.
44+
*
45+
* @return the total amount of elements
46+
*/
47+
int getTotalSize();
48+
49+
/**
50+
* The data of current page
51+
*
52+
* @return non-null {@link List}
53+
*/
54+
List<T> getData();
55+
56+
/**
57+
* The size of {@link #getData() data}
58+
*
59+
* @return positive integer
60+
*/
61+
default int getDataSize() {
62+
return getData().size();
63+
}
64+
65+
/**
66+
* Returns whether the page has data at all.
67+
*
68+
* @return
69+
*/
70+
default boolean hasData() {
71+
return getDataSize() > 0;
72+
}
73+
}

0 commit comments

Comments
 (0)