Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ming zheng
Spring Cloud Function
Commits
955e99bf
Commit
955e99bf
authored
7 years ago
by
Dave Syer
Browse files
Options
Download
Email Patches
Plain Diff
Re-org so that default methods are used everywhere
parent
33b33adb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionInspector.java
+6
-1
...ork/cloud/function/context/catalog/FunctionInspector.java
spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.java
+2
-1
...ntext/config/ContextFunctionCatalogAutoConfiguration.java
spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionExtractingFunctionCatalog.java
+47
-46
.../function/deployer/FunctionExtractingFunctionCatalog.java
with
55 additions
and
48 deletions
+55
-48
spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionInspector.java
+
6
-
1
View file @
955e99bf
...
...
@@ -16,6 +16,9 @@
package
org.springframework.cloud.function.context.catalog
;
import
java.util.Collections
;
import
java.util.Set
;
import
org.springframework.cloud.function.context.FunctionRegistration
;
/**
...
...
@@ -57,7 +60,9 @@ public interface FunctionInspector {
default
String
getName
(
Object
function
)
{
FunctionRegistration
<?>
registration
=
getRegistration
(
function
);
return
registration
==
null
?
null
:
registration
.
getNames
().
iterator
().
next
();
Set
<
String
>
names
=
registration
==
null
?
Collections
.
emptySet
()
:
registration
.
getNames
();
return
names
.
isEmpty
()
?
null
:
names
.
iterator
().
next
();
}
}
This diff is collapsed.
Click to expand it.
spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.java
+
2
-
1
View file @
955e99bf
...
...
@@ -160,7 +160,8 @@ public class ContextFunctionCatalogAutoConfiguration {
@Override
public
FunctionRegistration
<?>
getRegistration
(
Object
function
)
{
return
processor
.
getRegistration
(
function
);
FunctionRegistration
<?>
registration
=
processor
.
getRegistration
(
function
);
return
registration
;
}
}
...
...
This diff is collapsed.
Click to expand it.
spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionExtractingFunctionCatalog.java
+
47
-
46
View file @
955e99bf
...
...
@@ -100,9 +100,10 @@ public class FunctionExtractingFunctionCatalog
}
private
FunctionType
findType
(
Object
function
)
{
FunctionType
type
=
FunctionType
.
from
(
getInputType
(
function
))
.
to
(
getOutputType
(
function
)).
wrap
(
getInputWrapper
(
function
));
if
(
isMessage
(
function
))
{
FunctionType
type
=
FunctionType
.
from
((
Class
<?>)
type
(
function
,
"getInputType"
))
.
to
((
Class
<?>)
type
(
function
,
"getOutputType"
))
.
wrap
((
Class
<?>)
type
(
function
,
"getInputWrapper"
));
if
((
Boolean
)
type
(
function
,
"isMessage"
))
{
type
=
type
.
message
();
}
return
type
;
...
...
@@ -120,35 +121,10 @@ public class FunctionExtractingFunctionCatalog
return
(
Set
<
String
>)
getNames
(
"getNames"
,
type
);
}
@Override
public
boolean
isMessage
(
Object
function
)
{
return
(
Boolean
)
type
(
function
,
"isMessage"
);
}
@Override
public
Class
<?>
getInputType
(
Object
function
)
{
return
(
Class
<?>)
type
(
function
,
"getInputType"
);
}
@Override
public
Class
<?>
getOutputType
(
Object
function
)
{
return
(
Class
<?>)
type
(
function
,
"getOutputType"
);
}
@Override
public
Class
<?>
getInputWrapper
(
Object
function
)
{
return
(
Class
<?>)
type
(
function
,
"getInputWrapper"
);
}
@Override
public
Class
<?>
getOutputWrapper
(
Object
function
)
{
return
(
Class
<?>)
type
(
function
,
"getOutputWrapper"
);
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
String
getName
(
Object
function
)
{
return
((
Set
<
String
>)
inspect
(
function
,
"getNames"
)).
iterator
().
next
();
Set
<
String
>
names
=
getNames
(
function
);
return
names
.
isEmpty
()
?
null
:
names
.
iterator
().
next
();
}
public
String
deploy
(
String
name
,
String
path
,
String
...
args
)
{
...
...
@@ -216,21 +192,45 @@ public class FunctionExtractingFunctionCatalog
}
}
private
Object
inspect
(
Object
arg
,
String
method
)
{
private
Set
<
String
>
getNames
(
Object
arg
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Inspecting names"
);
}
@SuppressWarnings
(
"unchecked"
)
Set
<
String
>
result
=
(
Set
<
String
>)
invoke
(
FunctionInspector
.
class
,
"getRegistration"
,
this
::
extractNames
,
arg
);
return
result
;
}
private
Set
<
String
>
extractNames
(
String
id
,
Object
result
)
{
@SuppressWarnings
(
"unchecked"
)
Set
<
String
>
prefixed
=
(
Set
<
String
>)
prefix
(
id
,
invoke
(
result
,
"getNames"
));
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"
Inspecting "
+
metho
d
);
logger
.
debug
(
"
Result (from "
+
this
.
ids
.
get
(
id
)
+
"): "
+
prefixe
d
);
}
return
invoke
(
FunctionInspector
.
class
,
"getRegistration"
,
(
id
,
result
)
->
{
return
prefix
(
id
,
invoke
(
result
,
method
));
},
arg
);
if
(
prefixed
.
isEmpty
())
{
return
null
;
}
return
prefixed
;
}
private
Object
type
(
Object
arg
,
String
method
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Inspecting "
+
method
);
logger
.
debug
(
"Inspecting type "
+
method
);
}
Object
result
=
invoke
(
invoke
(
invoke
(
FunctionInspector
.
class
,
"getRegistration"
,
this
::
discardEmpty
,
arg
),
"getType"
),
method
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Result: "
+
result
);
}
return
invoke
(
invoke
(
invoke
(
FunctionInspector
.
class
,
"getRegistration"
,
arg
),
"getType"
),
method
);
return
result
;
}
private
Object
discardEmpty
(
String
id
,
Object
result
)
{
if
(
result
==
null
||
invoke
(
result
,
"getTarget"
)
==
null
)
{
return
null
;
}
return
result
;
}
private
Object
prefix
(
String
id
,
Object
result
)
{
...
...
@@ -252,9 +252,6 @@ public class FunctionExtractingFunctionCatalog
}
else
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Result (from "
+
name
+
"): "
+
result
);
}
return
result
;
}
}
...
...
@@ -279,7 +276,7 @@ public class FunctionExtractingFunctionCatalog
return
invoke
(
type
,
method
,
null
,
arg
);
}
private
Object
invoke
(
Class
<?>
type
,
String
method
,
Callback
callback
,
private
Object
invoke
(
Class
<?>
type
,
String
method
,
Callback
<?>
callback
,
Object
...
arg
)
{
Set
<
Object
>
results
=
new
LinkedHashSet
<>();
Object
fallback
=
null
;
...
...
@@ -301,7 +298,11 @@ public class FunctionExtractingFunctionCatalog
continue
;
}
if
(
callback
!=
null
)
{
return
callback
.
call
(
id
,
result
);
result
=
callback
.
call
(
id
,
result
);
if
(
result
!=
null
)
{
return
result
;
}
continue
;
}
return
result
;
}
...
...
@@ -338,7 +339,7 @@ public class FunctionExtractingFunctionCatalog
return
prefix
(
id
,
result
);
}
catch
(
Exception
e
)
{
throw
new
IllegalStateException
(
"Cannot extract
catalog
"
,
e
);
throw
new
IllegalStateException
(
"Cannot extract"
,
e
);
}
}
...
...
@@ -365,8 +366,8 @@ public class FunctionExtractingFunctionCatalog
return
result
;
}
interface
Callback
{
Object
call
(
String
id
,
Object
result
);
interface
Callback
<
T
>
{
T
call
(
String
id
,
Object
result
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment