Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_20230801
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
alx_20230801
Commits
a930bf1f
Commit
a930bf1f
authored
Aug 04, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Programy Async Dispatch
parent
ba401de1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
0 deletions
+109
-0
Async1.java
...rc/main/java/ogloszenia/klient_niskopoziomowy/Async1.java
+52
-0
Async2.java
...rc/main/java/ogloszenia/klient_niskopoziomowy/Async2.java
+49
-0
Utils.java
...src/main/java/ogloszenia/klient_niskopoziomowy/Utils.java
+8
-0
No files found.
OgloszeniaKlient/src/main/java/ogloszenia/klient_niskopoziomowy/Async1.java
0 → 100644
View file @
a930bf1f
package
ogloszenia
.
klient_niskopoziomowy
;
import
jakarta.xml.ws.Dispatch
;
import
jakarta.xml.ws.Response
;
import
jakarta.xml.ws.Service
;
import
ogloszenia.generated.OgloszeniaService
;
import
javax.xml.namespace.QName
;
import
javax.xml.transform.Source
;
import
javax.xml.transform.stream.StreamSource
;
import
java.io.StringReader
;
import
java.util.concurrent.ExecutionException
;
public
class
Async1
{
static
final
String
trescXML
=
"""
<o:readOne xmlns:o="
http:
//soap.ogloszenia/">
<
id
>
1
</
id
>
</
o:
readOne
>
""";
public static void main(String[] args) {
System.out.println("
Startujemy
...
");
OgloszeniaService service = new OgloszeniaService();
QName portName = OgloszeniaService.OgloszeniaPort;
Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
System.out.println("
Mam
Dispatchera
" + dispatch);
Utils utils = new Utils();
Source src = new StreamSource(new StringReader(trescXML));
System.out.println("
Wysy
ł
am
zapytanie
");
Response<Source> response = dispatch.invokeAsync(src);
System.out.println("
Zapytanie
zlecone
");
System.out.println("
lalalala
,
robi
ę
inne
rzeczy
");
boolean done = false;
do {
utils.czekaj(1000);
done = response.isDone();
System.out.println("
Czy
wynik
ju
ż
jest
?
" + done);
} while (!done);
try {
Source result = response.get();
System.out.println("
Wykonuje
to
w
ą
tek
nr
" + Thread.currentThread().getId() + "
" + Thread.currentThread().getName());
System.out.println("
Mam
wynik:
" + result);
utils.wypiszTransformerem(result);
System.out.println("
Gotowe
"
);
}
catch
(
InterruptedException
e
)
{
System
.
err
.
println
(
e
);
}
catch
(
ExecutionException
e
)
{
e
.
printStackTrace
();
}
}
}
OgloszeniaKlient/src/main/java/ogloszenia/klient_niskopoziomowy/Async2.java
0 → 100644
View file @
a930bf1f
package
ogloszenia
.
klient_niskopoziomowy
;
import
jakarta.xml.ws.Dispatch
;
import
jakarta.xml.ws.Response
;
import
jakarta.xml.ws.Service
;
import
ogloszenia.generated.OgloszeniaService
;
import
javax.xml.namespace.QName
;
import
javax.xml.transform.Source
;
import
javax.xml.transform.stream.StreamSource
;
import
java.io.StringReader
;
import
java.util.concurrent.ExecutionException
;
public
class
Async2
{
static
final
String
trescXML
=
"""
<o:readOne xmlns:o="
http:
//soap.ogloszenia/">
<
id
>
1
</
id
>
</
o:
readOne
>
""";
public static void main(String[] args) {
System.out.println("
Startujemy
...
");
OgloszeniaService service = new OgloszeniaService();
QName portName = OgloszeniaService.OgloszeniaPort;
Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
System.out.println("
Mam
Dispatchera
" + dispatch);
Utils utils = new Utils();
Source src = new StreamSource(new StringReader(trescXML));
System.out.println("
Wysy
ł
am
zapytanie
");
dispatch.invokeAsync(src, response -> {
try {
Source result = response.get();
System.out.println("
Wykonuje
to
w
ą
tek
nr
" + Thread.currentThread().getId() + "
" + Thread.currentThread().getName());
System.out.println("
Mam
wynik:
" + result);
utils.wypiszTransformerem(result);
System.out.println("
Gotowe
");
} catch (InterruptedException e) {
System.err.println(e);
} catch (ExecutionException e) {
e.printStackTrace();
}
});
System.out.println("
Zapytanie
zlecone
");
System.out.println("
lalalala
,
robi
ę
inne
rzeczy
");
utils.czekaj(1000);
System.out.println("
Koniec
programu
"
);
}
}
OgloszeniaKlient/src/main/java/ogloszenia/klient_niskopoziomowy/Utils.java
View file @
a930bf1f
...
@@ -28,4 +28,12 @@ public class Utils {
...
@@ -28,4 +28,12 @@ public class Utils {
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
}
}
public
void
czekaj
(
long
milis
)
{
try
{
Thread
.
sleep
(
milis
);
}
catch
(
InterruptedException
e
)
{
System
.
err
.
println
(
e
);
}
}
}
}
Write
Preview
Markdown
is supported
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