BrightSide Workbench Full Report + Source Code
PushPool.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.push.sender;
20 
21 import java.net.MalformedURLException;
22 import java.net.URISyntaxException;
23 import java.util.function.Consumer;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.turro.annotation.ElephantPlugin;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.http.URLUtil;
29 import org.turro.push.PushMessage;
30 import org.turro.string.Strings;
31 
36 @ElephantPlugin(label = "pool")
37 public class PushPool extends AbstractPushSender {
38 
39  @Override
40  protected void doSend(String title, String message, String link, Consumer onFinish) {
41  if(!assistants.isEmpty()) {
42  try {
43  link = Strings.isBlank(link) ? ElephantContext.getServerUrl("http") : URLUtil.absolute(ElephantContext.getServerUrl("http"), link);
44  String payload = PushMessage.title(title).message(message).click(link).json();
45  new PushPoolSender(assistants, payload).send(null);
46  } catch (URISyntaxException | MalformedURLException ex) {
47  Logger.getLogger(PushPool.class.getName()).log(Level.SEVERE, null, ex);
48  }
49  }
50  }
51 
52 }
static String getServerUrl(String scheme)
static String absolute(String appServer, String path)
Definition: URLUtil.java:77
static PushMessage title(String title)
PushMessage click(String target)
PushMessage message(String message)
void doSend(String title, String message, String link, Consumer onFinish)
Definition: PushPool.java:40